I am trying to wrap a Python script into an exe using PyInstaller (development version) for windows.

The script uses Pandas and I have been running into an error when running the exe.

Traceback (most recent call last):   File "site-packages\pandas\__init__.py", line 26, in <module>   File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)   File "site-packages\pandas\_libs\__init__.py", line 4, in <module>   File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_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 "G5k Version file Extract (with tkinter).py", line 15, in <module>   File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)   File "site-packages\pandas\__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.

I have tried doing this for programs without pandas and everything was fine.

This is very similar to another question already solved for Python 2, but I am using Python 3 and that solution does not apply the same way due to the changed .spec file format.

Python 3.6
PyInstaller – version 3.3
Pandas – version 0.20.3

PyInstaller 3.3, Pandas 0.21.0, Python 3.6.1.

I was able to solve this thanks to not-yet published/committed fix to PyInstaller, see this and this. AND keeping the ability to pack it into one executable file.


  1. Locate PyInstaller folder..\hooks, e.g. C:\Program Files\Python\Lib\site-packages\PyInstaller\hooks.

  2. Create file hook-pandas.py with contents (or anything similar based on your error):

    hiddenimports = ['pandas._libs.tslibs.timedeltas']
  3. Save it + I deleted .spec file, build and dist folders just to be sure.

  4. Run pyinstaller -F my_app.py.

This fix should work as long as you don’t upgrade or reinstall PyInstaller. So you don’t need to edit .spec file.

Maybe they will include the fix sooner for us! 🙂

I’m not sure it may help you but following the solution on the post you mention work for me with python 3.6 pyinstaller 3.3 and pandas 0.21.0 on windows 7.

So adding this to the spec file just after analysis :

def get_pandas_path():
    import pandas
    pandas_path = pandas.__path__[0]
    return pandas_path

dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)

Also my spec file format is the same as the one in the post you mention.

I managed to solve this problem by using the “–hidden-import” flag. Hopefully this can be helpful to someone else that comes across this thread.

pyinstaller --onefile --hidden-import pandas._libs.tslibs.timedeltas myScript.py

If you are using Anaconda, it is highly likely that when you were trying to uninstall some package it has disrupted pandas dependency and unable to get the required script. If you just run conda install pandas you might end up with another error:

module 'pandas' has no attribute 'compat'.

So, try uninstalling and reinstalling pandas conda uninstall pandas, Install it again using conda install pandas this will solve the problem.
On the other hand, if you are not using Anaconda., try doing the same on Command prompt pointing to Python scripts folder pip uninstall pandas & pip install pandas.

Most of the times, this should solve the problem. Just to be cover all the possibilities, don’t forget to Launch Spyder from Anaconda after installing pandas.