exe
build successfully by using cx-freeze. But it shows the following error when I execute the exe
file:
使用cx-freeze成功构建exe。但是当我执行exe文件时,会显示以下错误:
from . import _methods ImportError: cannot import name '_methods'
从。导入_methods ImportError:无法导入name '_methods'
2 个解决方案
#1
16
This question was already answer here: Why am I getting this ImportError? but for the sake of completeness here is the answer for this specific case: cx_freeze is not importing the optional module _method, so you have to tell him explicitly to do it.
这个问题已经在这里得到了答案:我为什么会有这种恐惧?但是为了完整性起见,这里给出了这个特定情况的答案: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')]
)
In the code above I have to import also format, after _methods. For me the 2 modules where enough, may be you need more.
在上面的代码中,我还必须导入_methods之后的format。对我来说,这两个模块足够了,也许你需要更多。
#2
1
Ok, I think we are in the same boat. i get the idea from the last post, but i'm not so familiar with the grammar and there is some different grammar with the last post in setup.py.
好吧,我想我们处境相同。我是从上一篇文章中得到这个想法的,但是我对语法不是很熟悉,在setup.py的最后一篇文章中有一些不同的语法。
But I get another way to solve this:
但是我有另一种方法来解决这个问题
add import numpy.core._methods
and import numpy.lib.format
in your python file.
添加进口numpy.core。_methods numpy.lib进口。在python文件中格式化。
#1
16
This question was already answer here: Why am I getting this ImportError? but for the sake of completeness here is the answer for this specific case: cx_freeze is not importing the optional module _method, so you have to tell him explicitly to do it.
这个问题已经在这里得到了答案:我为什么会有这种恐惧?但是为了完整性起见,这里给出了这个特定情况的答案: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')]
)
In the code above I have to import also format, after _methods. For me the 2 modules where enough, may be you need more.
在上面的代码中,我还必须导入_methods之后的format。对我来说,这两个模块足够了,也许你需要更多。
#2
1
Ok, I think we are in the same boat. i get the idea from the last post, but i'm not so familiar with the grammar and there is some different grammar with the last post in setup.py.
好吧,我想我们处境相同。我是从上一篇文章中得到这个想法的,但是我对语法不是很熟悉,在setup.py的最后一篇文章中有一些不同的语法。
But I get another way to solve this:
但是我有另一种方法来解决这个问题
add import numpy.core._methods
and import numpy.lib.format
in your python file.
添加进口numpy.core。_methods numpy.lib进口。在python文件中格式化。