Search code examples
pythonpyinstallerpy2execx-freeze

Creating executable file of my python script


I am trying to create an executable file out of my python script. System config :

python --version : 
                Python 2.7.15 :: Anaconda, Inc.
                conda : 4.3.16
                numpy : 1.14.3
                pandas : 0.23.4
                py2exe : 0.6.9
                pyinstaller : 3.4
                cx-Freeze : 5.1.1

Method 1: I tried pyinstaller but unfortunately it needs PyQt5 and since pyqt5 is not supported for python 2.7 environment I couldn't proceed with this method https://pypi.org/project/PyQt5/#files

Method 2: py2exe 1) python setup.py install 2) python setup.py py2exe but when I do run my exe file in cmd I get the following error

error:

X:\Data_Analytics\ETL\dist>Expiry.exe
Traceback (most recent call last):
  File "Expiry.py", line 5, in <module>
  File "pandas\__init__.pyc", line 19, in <module>
ImportError: Missing required dependencies ['numpy']

Setup code file :

from distutils.core import setup
import py2exe
import sys
sys.setrecursionlimit(5000)

setup(console=['Expiry.py'])

Method 3: cx_Freeze command: python setup.py build setup file:

from cx_Freeze import setup, Executable 

setup(name = "Expiry" , 
      version = "1.0" , 
      description = "" , 
      executables = [Executable("Expiry.py")]) 

Error:

X:\Data_Analytics\ETL\build\exe.win-amd64-2.7>Expiry.exe
Traceback (most recent call last):
  File "X:\Anaconda\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "X:\Anaconda\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "Expiry.py", line 5, in <module>
  File "X:\Anaconda\lib\site-packages\pandas-0.23.4-py2.7-win-amd64.egg\pandas\__init__.py", line 19, in <module>
    "Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']

I have tried reinstalling pandas and numpy also, tried reinstalling anaconda but no luck.


Solution

  • @jpeg as pointed out, here is my solution that worked after your recommendation.

    from cx_Freeze import setup, Executable 
    options = {'build_exe': {'packages': ['numpy'], 'include_files':['X:\Anaconda\Lib\site-packages\mkl_intel_thread.dll']} }
    
    setup(name = "Expiry" , 
           version = "1.0" , 
           description = "" ,
           options = options,  
           executables = [Executable("Expiry.py")])