Issues with freezing Python Pandas

Question:

I just upgraded from Python 2.7 to 3.6.
I have a rather large script with a GUI which I had frozen to an .exe file with pyinstaller.

I have now made a few changes to the .py script and it works with the new Python version before I freeze it.

However, when I freeze I get a “Failed to execute script” message.
I tried to look into the error code and I traced the issue to the Pandas module. Here is the error message:

C:UsersMRCHdist>My_File.exe
Traceback (most recent call last):
  File "site-packagespandas__init__.py", line 26, in <module>
  File "c:anaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packagespandas_libs__init__.py", line 4, in <module>
  File "c:anaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py", line 714, in load_module
    module = loader.load_module(fullname)
  File "pandas/_libs/tslib.pyx", line 1, in init pandas._libs.tslib
ModuleNotFoundError: No module named 'pandas._libs.tslibs.timedeltas'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "My_File.py", line 6, in <module>
  File "c:anaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packagespandas__init__.py", line 35, in <module>
ImportError: C extension: No module named 'pandas._libs.tslibs.timedeltas' not built. 
**If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.**
[2032] Failed to execute script My_File

The error message suggest to import pandas by running ‘python setup.py build_ext –inplace –force’ first. Where would I run this? It can’t find the setup.py file if I run it from cmd?

Asked By: Martin

||

Answers:

@apogalacticon Thanks!

Adding the following line to the .spec file solved the problem:

hiddenimports = ['pandas._libs.tslibs.timedeltas'] 
Answered By: Martin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.