0
Traceback (most recent call last):
  File "site-packages\pandas\__init__.py", line 26, in <module>
  File "C:\Users\adas\AppData\Local\Continuum\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\adas\AppData\Local\Continuum\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
    module = loader.load_module(fullname)
  File "pandas\_libs\tslibs\conversion.pxd", line 11, in init pandas._libs.tslib
  File "C:\Users\adas\AppData\Local\Continuum\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
    module = loader.load_module(fullname)
  File "pandas\_libs\tslibs\conversion.pyx", line 1, in init pandas._libs.tslibs.conversion
ModuleNotFoundError: No module named 'pandas._libs.tslibs.np_datetime'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "fetchall2.py", line 5, in <module>
    import pandas as pd
  File "C:\Users\adas\AppData\Local\Continuum\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.np_datetime' 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.
[283516] Failed to execute script fetchall2

I am trying to execute a python script i wrote. The script is supposed to create a PNG file based on the plot created by matplotlib. It works fine when I run it on the spyder IDE, but fails when I build it with PyInstaller.

using these imports

import MySQLdb
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('Agg')
import pandas as pd
from sklearn.preprocessing import Imputer, LabelEncoder, OneHotEncoder, StandardScaler
from sklearn import svm
from sklearn.cross_validation import train_test_split
from sklearn.linear_model import LinearRegression

I tried to follow Petr Szturc's Method and created a hooks-pandas.py file and with hiddenimports = ['pandas._libs.tslibs.tslibs.np_datetime'] but continue to get the same traceback.

Anaconda 4.5.11

Python 3.6

Adas
  • 404
  • 2
  • 19

1 Answers1

0

I think I've had same error in the past.

I have a pyinstaller_hooks directory in my project, and file hook-pandas.py with the following code:

from PyInstaller.utils.hooks import collect_submodules

hiddenimports = collect_submodules('pandas._libs.tslibs')

Then when running PyInstaller I pass the directory in the --additional-hooks-dir:

pyinstaller --additional-hooks-dir pyinstaller_hooks your_python_file.py

This makes it easy to identify what changes I have made for hooks, instead of mixing them into the PyInstaller folder, and they also are checked into any git repo. I think this is much cleaner than the method proposed in your link.

D Sievers
  • 156
  • 1
  • 4
  • i solved it by updating the hidden-imports field in the spec file generated by pyinstaller. I had to do it multiple times since every time i added a "missing imports" it will tell me I am missing another import. After like 10 builds and adding 10 hidden-imports the executable worked. Also you have to run the program.spec in cmd for your specs to take effect or it will get overwritten with a blank spec file. – Adas Sep 25 '18 at 14:08