【问题标题】:from . import _methods ImportError: cannot import name '_methods' in cx-freeze python从 。 import _methods ImportError: cannot import name '_methods' in cx-freeze python
【发布时间】:2017-06-03 18:36:54
【问题描述】:

exe 使用 cx-freeze 成功构建。但是当我执行exe 文件时它显示以下错误:

从 . import _methods ImportError: cannot import name '_methods'

【问题讨论】:

    标签: python python-3.4 cx-freeze


    【解决方案1】:

    这个问题已经在这里回答了:Why am I getting this ImportError? 但为了完整起见,这里是这个特定情况的答案:cx_freeze 没有导入可选模块 _method,所以你必须明确告诉他这样做。

    additional_mods = ['numpy.core._methods', 'numpy.lib.format']
    setup(name='xyz', 
          version='0.4', 
          description='xyz script',
          options = {'build_exe': {'includes': additional_mods}},
          executables = [Executable('xyz.py')]
        )
    

    在上面的代码中,我还必须在 _methods 之后导入 format。对我来说,两个模块足够了,可能你需要更多。

    【讨论】:

    • 谢谢鲁道夫!小错误:additional_mods(不是addtional_mods):)
    【解决方案2】:

    好吧,我想我们是在同一条船上。我从上一篇文章中得到了这个想法,但我对语法不是很熟悉,并且在 setup.py 中的最后一篇文章有​​一些不同的语法。

    但我有另一种方法来解决这个问题:

    在你的python文件中添加import numpy.core._methodsimport numpy.lib.format

    【讨论】:

    • 这是一个不需要 setup.py 的快速解决方案
    猜你喜欢
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多