Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyinstaller with pandas and numpy, exe throws error at runtime

I am trying to make an EXE using Pyinstaller of a small test program. I made a virtual environment to make the exe size smaller as anaconda includes every library it has.

ERROR at run time:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
  File "c:\users\madanr\appdata\local\continuum\anaconda3\envs\pyin36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pandas\__init__.py", line 19, in <module>
ImportError: Missing required dependencies ['numpy']
[15592] Failed to execute script test

I have already tried making a new environment with python35 and its the same error I installed numpy using pip and then installed all the other packages

test.py code:

import pandas as pd
import numpy as np

pdf = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
print(pdf)

pip freeze for my environment(pyin36)

altgraph==0.16.1
certifi==2018.11.29
future==0.17.1
macholib==1.11
numpy==1.16.0
pandas==0.23.4
pefile==2018.8.8
PyInstaller==3.4
pyodbc==4.0.25
pypiwin32==223
python-dateutil==2.7.5
pytz==2018.9
pywin32==224
pywin32-ctypes==0.2.0
scipy==1.2.0
six==1.12.0
wincertstore==0.2

I am posting >pyinstaller test.py cmd output here

121 INFO: PyInstaller: 3.4
121 INFO: Python: 3.6.8
122 INFO: Platform: Windows-10-10.0.16299-SP0
130 INFO: wrote C:\Users\MadanR\Desktop\Python Executables\Test\test.spec
136 INFO: UPX is not available.
153 INFO: Extending PYTHONPATH with paths
['C:\\Users\\MadanR\\Desktop\\Python '
 'Executables\\Test',
 'C:\\Users\\MadanR\\Desktop\\Python '
 'Executables\\Test']
158 INFO: checking Analysis
161 INFO: Building Analysis because Analysis-00.toc is non existent
165 INFO: Initializing module dependency graph...
172 INFO: Initializing module graph hooks...
178 INFO: Analyzing base_library.zip ...
8026 INFO: running Analysis Analysis-00.toc
8031 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\madanr\appdata\local\continuum\anaconda3\envs\pyin36\python.exe
10193 INFO: Caching module hooks...
10216 INFO: Analyzing C:\Users\MadanR\Desktop\Python Executables\Test\test.py
10346 INFO: Processing pre-find module path hook   distutils
11180 INFO: Processing pre-safe import module hook   six.moves
17163 INFO: Processing pre-find module path hook   site
17164 INFO: site: retargeting to fake-dir 'c:\\users\\madanr\\appdata\\local\\continuum\\anaconda3\\envs\\pyin36\\lib\\site-packages\\PyInstaller\\fake-modules'
20521 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
39249 INFO: Loading module hooks...
39250 INFO: Loading module hook "hook-distutils.py"...
39268 INFO: Loading module hook "hook-encodings.py"...
39567 INFO: Loading module hook "hook-lib2to3.py"...
39584 INFO: Loading module hook "hook-numpy.core.py"...
39884 INFO: Loading module hook "hook-numpy.py"...
39895 INFO: Loading module hook "hook-pandas.py"...
41840 INFO: Loading module hook "hook-pkg_resources.py"...
42584 INFO: Processing pre-safe import module hook   win32com
42977 INFO: Loading module hook "hook-pydoc.py"...
42980 INFO: Loading module hook "hook-pythoncom.py"...
43610 INFO: Loading module hook "hook-pytz.py"...
43816 INFO: Loading module hook "hook-pywintypes.py"...
44355 INFO: Loading module hook "hook-scipy.linalg.py"...
44364 INFO: Loading module hook "hook-scipy.py"...
44382 INFO: Loading module hook "hook-scipy.sparse.csgraph.py"...
44395 INFO: Loading module hook "hook-scipy.special._ellip_harm_2.py"...
44397 INFO: Loading module hook "hook-scipy.special._ufuncs.py"...
44406 INFO: Loading module hook "hook-setuptools.py"...
45322 INFO: Loading module hook "hook-sqlite3.py"...
45543 INFO: Loading module hook "hook-sysconfig.py"...
45547 INFO: Loading module hook "hook-win32com.py"...
46118 INFO: Loading module hook "hook-xml.dom.domreg.py"...
46121 INFO: Loading module hook "hook-xml.py"...
46266 INFO: Looking for ctypes DLLs
46332 INFO: Analyzing run-time hooks ...
46348 INFO: Including run-time hook 'pyi_rth_pkgres.py'
46350 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
46357 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
46396 INFO: Looking for dynamic libraries
72892 INFO: Looking for eggs
72892 INFO: Using Python library c:\users\madanr\appdata\local\continuum\anaconda3\envs\pyin36\python36.dll
72899 INFO: Found binding redirects:
[]
72948 INFO: Warnings written to C:\Users\MadanR\Desktop\Python Executables\Test\build\test\warn-test.txt
73287 INFO: Graph cross-reference written to C:\Users\MadanRDesktop\Python Executables\Test\build\test\xref-test.html
73433 INFO: checking PYZ
73433 INFO: Building PYZ because PYZ-00.toc is non existent
73439 INFO: Building PYZ (ZlibArchive) C:\Users\MadanR\Desktop\Python Executables\Test\build\test\PYZ-00.pyz
77493 INFO: Building PYZ (ZlibArchive) C:\Users\MadanR\Desktop\Python Executables\Test\build\test\PYZ-00.pyz completed successfully.
77615 INFO: checking PKG
77616 INFO: Building PKG because PKG-00.toc is non existent
77622 INFO: Building PKG (CArchive) PKG-00.pkg
77794 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
77810 INFO: Bootloader c:\users\madanr\appdata\local\continuum\anaconda3\envs\pyin36\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
77811 INFO: checking EXE
77812 INFO: Building EXE because EXE-00.toc is non existent
77815 INFO: Building EXE from EXE-00.toc
77817 INFO: Appending archive to EXE C:\Users\MadanRDesktop\Python Executables\Test\build\test\test.exe
77921 INFO: Building EXE from EXE-00.toc completed successfully.
77945 INFO: checking COLLECT
77945 INFO: Building COLLECT because COLLECT-00.toc is non existent
77961 INFO: Building COLLECT COLLECT-00.toc
97895 INFO: Building COLLECT COLLECT-00.toc completed successfully.
like image 268
Rishi Avatar asked Jan 22 '19 21:01

Rishi


People also ask

Why is the .exe file created by PyInstaller not working?

The most common reason a PyInstaller package fails is that PyInstaller failed to bundle a required file. Such missing files fall into a few categories: Hidden or missing imports: Sometimes PyInstaller can't detect the import of a package or library, typically because it is imported dynamically.

Does PyInstaller support pandas?

Pyinstaller will find pandas,so it's just.

Which is better PyInstaller or py2exe?

In PyInstaller it is easy to create one exe, By default both create a bunch of exes & dlls. In py2exe its easier to embed manifest file in exe, useful for run as administrator mode in windows vista and beyond. Pyinstaller is modular and has a feature of hooks to include files in the build that you like.

Does PyInstaller work with libraries?

PyInstaller does not include libraries that should exist in any installation of this OS. For example in GNU/Linux, it does not bundle any file from /lib or /usr/lib , assuming these will be found in every system.


1 Answers

There is definitely an issue between PyInstaller 3.4 and numpy 1.16 leading to the error you see. Until the issue is resolved, reverting numpy to 1.15.4 should work for you:

pip install numpy==1.15.4

Then rebuild your .exe with PyInstaller and try again.

like image 151
Steven Avatar answered Oct 30 '22 11:10

Steven