No module named builtins

淺唱寂寞╮ 提交于 2019-11-30 14:37:46

问题


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.

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".

The only other post I could find on this subject indicated that builtins is a python3 thing, but I'm running 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:


回答1:


I also found using 'pip install future' resolved this issue

I got the information from here: 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




回答2:


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.

Note that nosetests also fails without matplotlib, but I'm not sure adding matplotlib as a dependency makes much sense.

Source




回答3:


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.

With that as background, here is the answer:

There were 2 basic problems:

  1. 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.

  2. 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.

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()
)



回答4:


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.

>>> 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


来源:https://stackoverflow.com/questions/27495752/no-module-named-builtins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!