带有 pandas 和 numpy 的 Pyinstaller,exe 在运行时抛出错误
Pyinstaller with pandas and numpy, exe throws error at runtime
我正在尝试使用小型测试程序的 Pyinstaller 制作一个 EXE。
我创建了一个虚拟环境来缩小 exe 的大小,因为 anaconda 包含它拥有的每个库。
在 运行 时间出错:
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
我已经尝试使用 python35 创建一个新环境,但出现了同样的错误
我使用 pip 安装了 numpy,然后安装了所有其他包
test.py代码:
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 我的环境 (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
我正在发布 >pyinstaller test.py
此处 cmd 输出
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.
PyInstaller 3.4
和 numpy 1.16
之间肯定存在问题,导致出现您看到的错误。在问题解决之前,将 numpy
恢复为 1.15.4
应该对您有用:
pip install numpy==1.15.4
然后用 PyInstaller
重建你的 .exe
然后再试一次。
我正在尝试使用小型测试程序的 Pyinstaller 制作一个 EXE。 我创建了一个虚拟环境来缩小 exe 的大小,因为 anaconda 包含它拥有的每个库。
在 运行 时间出错:
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
我已经尝试使用 python35 创建一个新环境,但出现了同样的错误 我使用 pip 安装了 numpy,然后安装了所有其他包
test.py代码:
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 我的环境 (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
我正在发布 >pyinstaller test.py 此处 cmd 输出
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.
PyInstaller 3.4
和 numpy 1.16
之间肯定存在问题,导致出现您看到的错误。在问题解决之前,将 numpy
恢复为 1.15.4
应该对您有用:
pip install numpy==1.15.4
然后用 PyInstaller
重建你的 .exe
然后再试一次。