我遇到類似的問題,報告爲here,這似乎是一個未解決的問題。Numpy Pyinstaller ImportError:無法導入名稱multiarray
編譯一個exe後,pyinstaller構建引發以下錯誤,這很可能是由numpy的\核心\造成init.py
有一些suggestions,已與衝突的numpy的安裝,但是我必須做卸載並重新安裝好幾次,並搜索其他任何安裝,但沒有運氣。 當前使用numpy-1.9 + MKL二進制文件運行。
我還將multiarray.pyd文件標記爲spec文件作爲要抓取的二進制文件。沒有運氣。
不知道是什麼原因造成的,因爲我對init文件結構不是特別熟悉。任何想法如何得到這個導入?
回溯錯誤:
Traceback (most recent call last):
File "<string>", line 50, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\mpl_toolkits.basemap", line 15, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\matplotlib", line 133, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\matplotlib.rcsetup", line 19, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\matplotlib.colors", line 52, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\numpy", line 200, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\numpy.add_newdocs", line 13, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\numpy.lib", line 8, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\numpy.lib.type_check", line 11, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\numpy.core", line 14, in <module>
ImportError: cannot import name multiarray
從init文件所採取的問題
可能的原因:
from __future__ import division, absolute_import, print_function
from .info import __doc__
from numpy.version import version as __version__
# disables OpenBLAS affinity setting of the main thread that limits
# python threads or processes to one core
import os
envbak = os.environ.copy()
if 'OPENBLAS_MAIN_FREE' not in os.environ:
os.environ['OPENBLAS_MAIN_FREE'] = '1'
if 'GOTOBLAS_MAIN_FREE' not in os.environ:
os.environ['GOTOBLAS_MAIN_FREE'] = '1'
from . import multiarray
os.environ.clear()
os.environ.update(envbak)
del envbak
del os
from . import umath
from . import _internal # for freeze programs
from . import numerictypes as nt
multiarray.set_typeDict(nt.sctypeDict)
中的文件後,您可以重新安裝numpy。我有一種感覺,這與numpy.core模塊中缺少.py文件有關。只有pyd文件存在,但init文件試圖導入模塊多陣列。 – Praxis
@Richard Snape - 代碼可以在python 2.7中從控制檯和Pycharm運行良好。只有當exe運行時發生錯誤,所以我認爲這是一個numpy-pyinstaller兼容性問題。 我想知道如果從.pyd文件反編譯爲.py可能是一個解決方案。錯誤的來源是。 線14 init.py電話:「進口多陣列」 numpy的可明顯處理動態加載.pyd不是編譯時,但可能需要一個.py文件時,它是在一個exe凍結。 – Praxis
感謝理查德,我真的很感謝你對這個問題的幫助 – Praxis