python - Numpy Pyinstaller 导入错误 : cannot import name multiarray

标签 python numpy build pyinstaller

我遇到了与报告的问题类似的问题 here ,这似乎是一个悬而未决的问题。

编译一个exe后,一个pyinstaller build抛出如下错误,这很可能是numpy\core\init.py引起的

有一些suggestions它与冲突的 numpy 安装有关,但是我已经卸载并重新安装了好几次,并且在没有运气的情况下搜索了任何其他安装。 当前使用 numpy-1.9+MKL 二进制文件运行。

我还将 multiarray.pyd 文件标记为要抓取的二进制文件。运气不好。

不知道是什么原因造成的,因为我对 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)

最佳答案

在交换评论后,问题被隔离为 OP 使用的自定义 .spec 文件中的问题。在 .spec 中,一行类似于:

coll = COLLECT(exe,
           a.binaries,
           a.zipfiles,
           a.datas,
           strip=None,
           upx=True,
           name='nptest')

已被替换为

coll = COLLECT(exe,
           a.binaries1,
           a.zipfiles,
           a.datas,
           strip=None,
           upx=True,
           name='nptest')

尝试引入文件 a.binaries1 以使 pyinstaller 能够使用一些自定义的 .dll 二进制文件。

面对 a.binariesAnalysis 对象的成员并且需要保留 - 在 collect 行中添加额外的二进制 gile 的方式是这样的( as per the docs)。请注意,您可以通过更改元组的第一个成员来更改分发中文件的名称(如果需要)。

coll = COLLECT(exe,
           a.binaries+[('zipcontainer.dll','C:\\Windows\\System32\\zipcontainer.dll','BINARY')],
           a.zipfiles,
           a.datas,
           strip=None,
           upx=True,
           name='nptest')

关于python - Numpy Pyinstaller 导入错误 : cannot import name multiarray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32820555/

相关文章:

python - Numpy:找到两个 3-D 数组之间的欧氏距离

python - 如何在numpy中返回所有最小索引

c# - 为什么网站项目在config中没有release模式?

python - pandas to_excel() 使用 float_format 参数 --> ValueError : could not convert string to float

python - IntegrityError : (1048, "Column ' username' cannot be null") when emailid is also unique key

python - 将滑动窗口设置为多维数组中的列(来自 MATLAB 的 IM2COL) - Python

c# - 构建原生 C++ 以用作 .net 库

python - 可视化 pandas/numpy 中的共现矩阵

python - 具有固定峰值的抛物线拟合

c++ - std::map insert 由于 "cannot convert argument 1 from ' 而无法编译 std::pair<MyKey, MyValue >' to ' std::pair<const _Kty,_Ty> & &'"