PyInstaller and Pandas

I have a pretty simple Python module that I am trying to compile into a Windows .exe file. In my script, I use the wxPython and Pandas libraries. The PyInstaller.exe file that is generated only works / opens when the Pandas library is excluded from my module.

I get the same issue if I --onefile or --onedir in PyInstaller. On the Internet, I discovered that the β€œnew” version of PyInstaller (2.1) was supposed to take care of this error. Anyone have any ideas what to do?

 PyInstaller: version 2.1 pandas: version 0.15.2 Python: version 2.7 
+16
source share
5 answers

I ran into the same problem. I welded it to a simple script, like this Hello.py:

 import pandas print "hello world, pandas was imported successfully!" 

In order to get pandas to import at runtime correctly, I had to change Hello.spec to the following:

 # -*- mode: python -*- block_cipher = None def get_pandas_path(): import pandas pandas_path = pandas.__path__[0] return pandas_path a = Analysis(['Hello.py'], pathex=['C:\\ScriptsThatRequirePandas'], binaries=None, datas=None, hiddenimports=[], hookspath=None, runtime_hooks=None, excludes=None, win_no_prefer_redirects=None, win_private_assemblies=None, cipher=block_cipher) 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) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, exclude_binaries=True, name='Hello', debug=False, strip=None, upx=True, console=True ) scoll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=None, upx=True, name='Hello') 

Then I ran:

 $pyinstaller Hello.spec --onefile 

from the command line and received the message "hello world", which I expected. I still do not quite understand why this is necessary. I have a custom pandas assembly - which is connected to MKL libraries, but it is not clear to me that this causes a runtime failure.

This is similar to the answer here: Pyinstaller does not adjust pycripto import ... sometimes

+19
source

I had a similar problem with pyinstaller version 3.3. The solution was that there was no covert capture, as described here

I created a new file under Pyinstaller / hooks / called hook-pandas.py and placed the contents as described in this commit here and reinstall pyinstaller manually by installing python setup.py in the Pyinstaller directory.

The problem did not recur when I created exe from my pandas script using pyinstaller using the -onefile option.

+11
source

Like another solution, adding --hidden-import=pandas._libs.tslibs.timedelta or something else that the module is missing from the pyinstaller also works.

This can be useful if you do not want to touch the source pyinstaller.

0
source

I solved the same problem using the traps file in the project directory (according to the pyinstaller document), hook-pandas.py

 hiddenimports = [ 'pandas._libs.tslibs.timedeltas', 'pandas._libs.tslibs.nattype', 'pandas._libs.tslibs.np_datetime', 'pandas._libs.skiplist', ] 

then adding one line to the specification file:

 ... a = Analysis([... hookspath=['.'], ...], ... 

I tried to include hiddenimports=[..., 'pandas',...] in the spec file, something did not work out as expected.

0
source

Hope this helps anyone having

 'ModuleNotFoundError: No module named 'sklearn.*'' 'ModuleNotFoundError: No module named 'h5py.*'' 'ModuleNotFoundError: No module named 'sklearn.*'' 

During or after the pyinstaller build

Example if you get an error for h5py

After running pyinstaller myscript.py myscript.spec generated

myscript.spec inside myscript.spec

 # -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis(['myscript.py'], binaries=None, datas=[], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None) # ... rest of a file untouched 

add

 from PyInstaller.utils.hooks import collect_submodules hidden_imports = collect_submodules('h5py') 

and

 hiddenimports=hidden_imports, 

Like this

 # -*- mode: python ; coding: utf-8 -*- block_cipher = None from PyInstaller.utils.hooks import collect_submodules hidden_imports = collect_submodules('h5py') a = Analysis(['myscript.py'], binaries=None, datas=[], hiddenimports=hidden_imports, hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None) # ... rest of a file untouched 

Then save myscript.spec and run the pyinstaller myscript.spec

Credit 9dogs Pyinstaller created EXE file cannot load model Keras NN

0
source

Source: https://habr.com/ru/post/983931/


All Articles