Python 没有名为 builtins 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27495752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No module named builtins
提问by Charlie_M
I'm trying to convert my .py script into an executable using py2exe. I've had a number of issues so far that have been largely addressed by the "options" in the setup file below. But now I have a problem that I have not been able to find a solution for, and wondering if others have had this same issue and fixed it.
我正在尝试使用 py2exe 将我的 .py 脚本转换为可执行文件。到目前为止,我遇到了许多问题,这些问题在很大程度上已由下面安装文件中的“选项”解决。但是现在我遇到了一个我无法找到解决方案的问题,想知道其他人是否也遇到过同样的问题并修复了它。
When I execute the setup file below using "python setup.py py2exe" it gives me an executable but when I run it, it complains "No module named builtins".
当我使用“python setup.py py2exe”执行下面的安装文件时,它给了我一个可执行文件,但是当我运行它时,它会抱怨“没有名为内置模块的模块”。
The only other post I could find on this subject indicated that builtins is a python3 thing, but I'm running 2.7.
我能找到的关于这个主题的唯一其他帖子表明内置是 python3 的东西,但我正在运行 2.7。
Appreciate any advice or tips on this.
感谢您对此的任何建议或提示。
from distutils.core import setup
import py2exe
from distutils.filelist import findall
import os
import matplotlib
matplotlibdatadir = matplotlib.get_data_path()
matplotlibdata = findall(matplotlibdatadir)
setup(
console=['DET14.py'],
options={
'py2exe': {
'packages' : ['matplotlib', 'pytz'],
'dll_excludes':['MSVCP90.DLL',
'libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'libgdk_pixbuf-2.0-0.dll'],
'includes':['scipy.sparse.csgraph._validation',
'scipy.special._ufuncs_cxx']
}
},
# data_files=matplotlibdata_files
data_files=matplotlib.get_py2exe_datafiles()
)
Here is the full listing of what the error message looks like:
以下是错误消息的完整列表:
采纳答案by Charlie_M
I finally got this working. It turned out that I had some errors in the original setup file, some of which were outright dumb, and some simply relfected my lack of understanding of how the parameters of the setup command works. I will add that this latter class of errors was only resolved with some Shelock Holmes-style sleuthing and plain old trial and error. By that I mean that I have still not found any documentation that calls out the meaning and usage of the parameters of the setup command. If anyone has that info and could pass it along that woudl be much appreciated.
我终于得到了这个工作。原来我在原来的安装文件中有一些错误,其中一些是彻头彻尾的愚蠢,还有一些只是反映了我对 setup 命令的参数如何工作缺乏了解。我要补充的是,后一类错误只能通过一些 Shelock Holmes 式的侦探和简单的旧试错来解决。我的意思是我仍然没有找到任何说明 setup 命令参数含义和用法的文档。如果有人拥有该信息并且可以将其传递给我们,我们将不胜感激。
With that as background, here is the answer:
以此为背景,答案如下:
There were 2 basic problems:
有2个基本问题:
The list of packages in the aboe setup file was woefully incomplete. I am still not certain that the rule is that you have to list every single package that your program relies upon, and some which it may rely upon that you didn't know about (i.e., pytz, for example...). But when I did that, I had something at that point that I could eventually get to work.
The error message in the above original question sort of looks like my program had a dependence on a thing called "patsy", andthis confused me because I had no idea what that is, but it turns out that statsmodels (whihc is core to my project) has a dependency on patsy, so it needed to be included in the "packages" list.
aboe 安装文件中的软件包列表非常不完整。我仍然不确定规则是您必须列出程序所依赖的每个包,以及它可能依赖的一些您不知道的包(例如,pytz...)。但是当我这样做时,我在那个时候有了一些我最终可以开始工作的东西。
上面原始问题中的错误消息有点像我的程序依赖于一个叫做“patsy”的东西,这让我很困惑,因为我不知道那是什么,但结果是 statsmodels(这是我项目的核心) 依赖于 patsy,因此需要将其包含在“包”列表中。
Below is the setup file that ended up working. I hope this description of the logic behind the fix turns out to be helpful to others facing the same kind of problem.
下面是最终工作的安装文件。我希望这个修复背后的逻辑描述对面临同样问题的其他人有所帮助。
from distutils.core import setup
import py2exe
from distutils.filelist import findall
import os
import matplotlib
matplotlibdatadir = matplotlib.get_data_path()
matplotlibdata = findall(matplotlibdatadir)
setup(
console=['DET14.py'],
options={
'py2exe': {
'packages' : ['matplotlib', 'pytz','easygui',\
'statsmodels','pandas','patsy'],
'dll_excludes':['MSVCP90.DLL',
'libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'libgdk_pixbuf-2.0-0.dll'],
'includes':['scipy.sparse.csgraph._validation',
'scipy.special._ufuncs_cxx']
}
},
data_files=matplotlib.get_py2exe_datafiles()
)
回答by Sarah Rose
I also found using 'pip install future' resolved this issue
我还发现使用“pip install future”解决了这个问题
I got the information from here: https://askubuntu.com/questions/697226/importerror-no-module-named-builtins
我从这里得到了信息:https: //askubuntu.com/questions/697226/importerror-no-module-named-builtins
I hope this clarifies this for other users, like me who stumbled upon your question
我希望这可以为其他用户澄清这一点,比如我偶然发现了你的问题
回答by Akash Kandpal
Running pip install future
fixed this error for me.
For compatibility with Python2.7, the package future should be added to the install_requires in setup.py.
运行pip install future
为我修复了这个错误。为了与 Python2.7 兼容,应将包 future 添加到 setup.py 中的 install_requires 中。
Note that nosetests
also fails without matplotlib, but I'm not sure adding matplotlib as a dependency makes much sense.
请注意,nosetests
没有 matplotlib 也会失败,但我不确定将 matplotlib 添加为依赖项是否有意义。
回答by Peter
In case pip install future
does not work for you, it's possible that you have a bad copy of the future module hiding somewhere. For me, PyCharm had installed future==0.18
while I wanted future=0.16
. sudo pip uninstall future
did not work, you could still import future and it would be 0.18
. Solution was to find and delete it.
如果pip install future
对您不起作用,您可能在某处隐藏了未来模块的错误副本。对我来说,PyCharm 已经future==0.18
在我想要的时候安装了future=0.16
。 sudo pip uninstall future
没有用,你仍然可以导入未来,它会是0.18
. 解决方法是找到并删除它。
>>> import future
>>> future.__version__
'0.18.0'
>>> future.__file__
'/home/<USERNAME>/.local/lib/python2.7/site-packages/future/__init__.pyc'
rm -rf /home/<USERNAME>/.local/lib/python2.7/site-packages/future