问题描述
在使用Nuitka打包基于PythonOCC(OCC)库的软件时,虽然成功生成了exe文件,但在运行时遇到了numpy导入错误。
报错信息如下
D:AutoPoint>main.exe
[PyInstaller Patch] Running in Dev mode.
[PyInstaller Patch] Setting CSF_RESOURCES to: C:\Users\s\AppData\Local\Temp\ONEFIL~1\resources
[PyInstaller Patch] Setting CSF_FONTS to: C:\Users\s\AppData\Local\Temp\ONEFIL~1\fonts
Traceback (most recent call last):
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\numpy\**init**.py", line 114, in <module numpy>
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\numpy\**config**.py", line 4, in <module numpy.**config**>
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\numpy\_core\**init**.py", line 23, in <module numpy._core>
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\numpy\_core\[multiarray.py](http://multiarray.py/)", line 10, in <module numpy._core.multiarray>
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\numpy\_core\[overrides.py](http://overrides.py/)", line 8, in <module numpy._core.overrides>
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
RuntimeError: Nuitka: import of module 'numpy' failed unexpectedly despite intended perfect support, please raise a Nuitka issue and compile with an older version of the module in the meantime
Traceback (most recent call last):
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\[main.py](http://main.py/)", line 60, in <module>
from ui_mainwindow import MainWindow
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\ui_mainwindow.py", line 15, in <module ui_mainwindow>
from OCC.Display.qtDisplay import qtViewer3d
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\OCC\Display\[qtDisplay.py](http://qtdisplay.py/)", line 23, in <module OCC.Display.qtDisplay>
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\OCC\Core\[AIS.py](http://ais.py/)", line 406, in <module OCC.Core.AIS>
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\OCC\Core\[SelectMgr.py](http://selectmgr.py/)", line 406, in <module OCC.Core.SelectMgr>
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\OCC\Core\[Graphic3d.py](http://graphic3d.py/)", line 409, in <module OCC.Core.Graphic3d>
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\OCC\Core\[gp.py](http://gp.py/)", line 406, in <module [OCC.Core.gp](http://occ.core.gp/)>
File "C:\Users\s\AppData\Local\Temp\ONEFIL~1\OCC\Core\[TColStd.py](http://tcolstd.py/)", line 15, in <module OCC.Core.TColStd>
ImportError: numpy._core.multiarray failed to import
解决方法
将虚拟环境中numpy版本降级到1.25.2,可解决这个问题。
pip install numpy==1.25.2
后续在使用这个命令进行打包,最后成功运行exe文件。(注意调整自己需要的plugin和package)
nuitka --onefile --standalone ^
--enable-plugin=pyqt5 ^
--include-package=numpy ^
--include-package-data=numpy ^
main.py
conda环境说明
# Name Version Build Channel
numpy 1.25.2 pypi_0 pypi
occt 7.8.1 all_hae6dad1_203 conda-forge
python 3.9.23 h8c5b53a_0_cpython conda-forge
pythonocc-core 7.8.1.1 all_h3e79b3e_200 conda-forge

被折叠的 条评论
为什么被折叠?



