Numpy Pyinstaller ImportError:无法导入名称多阵列

时间:2015-09-28 10:15:06

标签: python numpy build pyinstaller

我遇到了类似问题here,这似乎是一个未解决的问题。

编译exe后,pyinstaller build会抛出以下错误,这可能是由numpy \ core \ 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)

2 个答案:

答案 0 :(得分:3)

在评论中进行交换后,问题被隔离为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')

答案 1 :(得分:1)

我在64位Windows 10上使用Pycharm IDE和Anaconda。

我通过以下序列解决了这个问题:

  1. 卸载anaconda中的numpy;
  2. 删除文件夹C:\ Users(COMPUTER NAME)\ AppData \ Roaming \ Python \ Python35 \ site-packages
  3. 中的相关numpy文件
  4. 在Anaconda中重新安装numpy
  5. 在你的情况下,我想你可以在删除文件夹C:\ Python27 \ Lib \ site-packages \ PyInstaller \ loader \

    中的文件后重新安装numpy