I want to build single-file executable on Windows 10 that uses pandas. Following is the totality of my single-file script TrivialTest.py
:
import numpy as np
import pandas as pd
np.random.seed(456)
j = [(a, b) for a in ['A','B','C'] for b in pd.date_range('2018-01-01', periods=5, freq='W')]
i = pd.MultiIndex.from_tuples(j, names=['Name','Num'])
df = pd.DataFrame(np.random.randn(15), i, columns=['Vals'])
df.to_csv('Test.csv')
So I run pyinstaller --onefile TrivialTest.py
and after several minutes find a dist
subfolder containing a TrivialTest.exe
.
When I try to run that .exe
I (eventually) get the following console output:
Traceback (most recent call last):
File "site-packages\pandas\__init__.py", line 26, in <module>
File "c:\programdata\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:\programdata\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 "TrivialTest.py", line 2, in <module>
File "c:\programdata\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.
[18776] Failed to execute script TrivialTest
I don't know if these are spurious or misleading errors. What's going wrong, and how do I overcome this?