0

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?

feetwet
  • 3,248
  • 7
  • 46
  • 84
  • how about running `python setup.py build_ext --inplace --force`? – NewNewton Apr 07 '18 at 18:07
  • @A.Wenn – where should I run that, what should it do, and what should I expect the result to be? – feetwet Apr 07 '18 at 18:10
  • Does it work without `--onefile` flag? What is the contents of the resulting package? Does it contain any traces of `pandas` module? – Ivan Aksamentov - Drop Apr 07 '18 at 18:20
  • @Drop: Many, many traces of pandas in `dist\TrivialTest`! If I try without `--onefile` maybe I don't know how I'm supposed to run this: Calling `build\TrivialTest.exe` from a default command prompt results in `Error loading Python DLL 'D:\Test\build\TrivialTest\python36.dll'. LoadLibrary: The specified module could not be found.` – feetwet Apr 07 '18 at 18:26
  • Surprisingly it's a duplicate question =) – Ivan Aksamentov - Drop Apr 07 '18 at 18:31

0 Answers0