1

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.

3

2 Answers 2

2
  1. You should be able to run the following commands without errors in a Python console:

    import numpy
    print numpy.__version__
    import pandas
    print pandas.__version__
    

    If this does not work, you first need to (re-)install numpy and pandas in this order.

  2. In order to freeze a script depending on pandas (and thus on numpy) with cx_Freeze, you need to explicitly add numpy to the packages list of the build_exe options. Try with the following modification of your setup script:

     from cx_Freeze import setup, Executable 
    
     options = {'build_exe': {'packages': ['numpy']}}
    
     setup(name = "Expiry" , 
           version = "1.0" , 
           description = "" ,
           options = options,  
           executables = [Executable("Expiry.py")])
    

    See Creating cx_Freeze exe with Numpy for Python.

Sign up to request clarification or add additional context in comments.

3 Comments

it worked, exe got created but now i am facing new error: Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
@KrishnaKumar This probably has to do with the way Anaconda handles packages. You probably need to explicitely tell cx_Freeze to include the DLL using the build_exe option include_files. Where is mkl_intel_thread.dll? (should be somwhere in X:\Anaconda\lib\site-packages\ )
i dont find this mkl_intel_thread.dll in my X:\Anaconda\lib\site-packages\ do i need to download and place in this directory, also this will be the changes right? options = {'build_exe': {'packages': ['numpy'], 'include_files ':['X:\Anaconda\Lib\site-packages\mkl_intel_thread.dll']} } i am bit naive to all this pls help
1

@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")])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.