【问题标题】:cx_freeze - ImportError: numpy.core.multiarray failed to importcx_freeze - ImportError: numpy.core.multiarray 导入失败
【发布时间】:2017-12-05 12:48:21
【问题描述】:

在构建我的 exe 后,当我运行它时,我收到一条错误消息,提示它无法导入 numpy.core.multiarray。

我已经测试过的:

  • 已将 numpy 更新到最新版本
  • 检查我是否有多个版本的 numpy
  • 文件 multiarray 位于 build/../numpy/core/multiarray 中
  • 如果我在控制台上运行 python,我可以“从 numpy.core 导入多数组”没有任何问题

我使用的包:Easygui、Opencv2、pytesseract、os、pillow、regex

我在 W10 上运行 python 3.6.1

这是我的 setup.py。

    from cx_Freeze import setup, Executable
    import os

    os.environ['TCL_LIBRARY'] = r'C:\Users\Farinha\Anaconda3\tcl\tcl8.6'
    os.environ['TK_LIBRARY'] = r'C:\Users\Farinha\Anaconda3\tcl\tk8.6'

    includes      = []
    include_files = [r"C:\Users\Farinha\Anaconda3\DLLs\tcl86t.dll", \
                     r"C:\Users\Farinha\Anaconda3\DLLs\tk86t.dll"]


    setup(name='InstantScale',
        version = '0.1',
        description='Parse stuff',
        options = {"build_exe": {"includes": includes, "include_files": include_files}},
        executables = [Executable("main.py")])

当我运行 bat 暂停控制台时的错误

ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
  File "C:\Users\Farinha\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Users\Farinha\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "main.py", line 2, in <module>
ImportError: numpy.core.multiarray failed to import

欢迎大家帮忙,提前致谢

【问题讨论】:

    标签: python numpy cx-freeze


    【解决方案1】:

    将 numpy 包直接复制到您的目录中。

    然后添加这些行:

    import numpy.core._methods 
    import numpy.lib.format
    

    more information in this post

    【讨论】:

      【解决方案2】:

      我设法修复它。

      我手动将包添加到选项中。

      includes      = []
      include_files = [r"C:\Users\Farinha\Anaconda3\DLLs\tcl86t.dll", \
                       r"C:\Users\Farinha\Anaconda3\DLLs\tk86t.dll"]
      packages = ["numpy"]
      
      setup(name='InstantScale',
          version = '0.1',
          description='Parse stuff',
          options = {"build_exe":{"includes": includes, "include_files": 
                include_files, "packages":packages}}
      

      【讨论】:

        【解决方案3】:

        在我的情况下,在 cxFreeze 选项中使用 optimize=2 时发生了错误。更多信息:https://github.com/numpy/numpy/issues/13248

            setup(name='InstantScale',
                version = '0.1',
                description='Parse stuff',
                options = {"build_exe": {"optimize": 1}},
                executables = [Executable("main.py")])
        

        【讨论】:

          猜你喜欢
          • 2016-12-07
          • 2019-06-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-11-04
          • 2021-02-25
          • 2016-03-07
          • 2022-08-13
          相关资源
          最近更新 更多