I'm running into an issue with cx_Freeze
when running a frozen application (works fine unfrozen).
在运行一个冻结的应用程序时,我遇到了一个cx_Freeze的问题(运行良好的unfrozen)。
When running the program it results in the following traceback:
在运行程序时,它会导致以下回溯:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 27, in <module>
exec code in m.__dict__
File "PythonApp/mainframe.py", line 3, in <module>
File "/usr/local/lib/python2.7/site-packages/dbus/__init__.py", line 103, in <module>
from dbus._dbus import Bus, SystemBus, SessionBus, StarterBus
File "/usr/local/lib/python2.7/site-packages/dbus/_dbus.py", line 39, in <module>
from dbus.bus import BusConnection
File "/usr/local/lib/python2.7/site-packages/dbus/bus.py", line 39, in <module>
from dbus.connection import Connection
File "/usr/local/lib/python2.7/site-packages/dbus/connection.py", line 27, in <module>
import threading
File "/usr/local/lib/python2.7/threading.py", line 44, in <module>
module='threading', message='sys.exc_clear')
File "/usr/local/lib/python2.7/warnings.py", line 57, in filterwarnings
import re
File "/usr/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/usr/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/usr/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/usr/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
I'm on linux using a version of python 2.7.4 that I built from source, and importing _sre
from a prompt works and I can access the MAXREPEAT
constant.
我在linux上使用的是python 2.7.4版本,这是我从源代码构建的,从一个提示工作中导入_sre,我可以访问MAXREPEAT常量。
This is usually down to cx_Freeze
not pulling everything into library.zip
and can be fixed by explicitly naming the module in cx_Freeze
s setup include list and is the solution to this similar question, but that hasn't helped here.
这通常是cx_Freeze,而不是把所有东西都拖进库中。zip可以通过显式地命名cx_冻结设置中的模块来固定,包括列表,也是这个类似问题的解决方案,但这在这里并没有帮助。
This _sre
module seems weird.. there's no _sre
file in the library.zip
generated but from that error it seems like it can find it, however it can't import that symbol? Surely if the module wasn't there it would be a "No module named _sre
" error. Or possibly a circular import but _sre
stub doesn't have any imports.
这个_sre模块看起来很奇怪。库中没有_sre文件。zip生成了,但是从那个错误中它似乎可以找到它,但是它不能导入那个符号?当然,如果模块不存在,它将是一个“没有命名的模块”错误。或者可能是一个循环导入,但是_sre存根没有任何导入。
What's odd is I can't seem to find the file either - is this module dynamically created when importing somehow?
奇怪的是,我似乎也找不到文件——这个模块是在导入时动态创建的吗?
find /usr/local/lib/python2.7 -name "_sre*"
doesn't return anything, and the imported _sre
module doesn't have a __file__
attribute either, so I've no idea how to make sure it's included as it shows up as a built-in.
没有返回任何东西,而导入的_sre模块也没有__file__属性,所以我不知道如何确保它包含在它作为内置的元素中。
>>> import _sre
>>> _sre.__file__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
>>> repr(_sre)
"<module '_sre' (built-in)>"
This is similar to this question also which was asked recently, but in this case he was getting the error in the regular interpreter, however for me it's just in cx_Freeze
.
这和最近被问到的这个问题很相似,但是在这个例子中,他在常规解释器中得到了错误,但是对我来说,它只是在cx_Freeze中。
edit
Running python -v
does seem like it's a built-in, so I'm not sure why cx_Freeze
can miss it, or how I'd fix it.
运行python -v看起来好像是内置的,所以我不知道为什么cx_Freeze会错过它,或者我如何修复它。
...
# /usr/local/lib/python2.7/re.pyc matches /usr/local/lib/python2.7/re.py
import re # precompiled from /usr/local/lib/python2.7/re.pyc
# /usr/local/lib/python2.7/sre_compile.pyc matches /usr/local/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/local/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/local/lib/python2.7/sre_parse.pyc matches /usr/local/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/local/lib/python2.7/sre_parse.pyc
...
6 个解决方案
#1
14
_sre
is a built in module, so there's no file to include for it, but it doesn't have a MAXREPEAT attribute in Python 2.7.3:
_sre是在模块中构建的,所以没有包含它的文件,但是它在Python 2.7.3中没有MAXREPEAT属性:
>>> import _sre
>>> _sre
<module '_sre' (built-in)>
>>> _sre.MAXREPEAT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'MAXREPEAT'
My best guess is that your frozen copy somehow has the standard library .py modules from Python 2.7.4, but the compiled Python interpreter from 2.7.3 or an earlier version. I see you're working from /usr/local
- maybe it's picking up an older version from /usr
.
我最好的猜测是,您的frozen copy某种程度上拥有来自Python 2.7.4的标准库.py模块,但是编译过的Python解释器来自2.7.3或更早的版本。我看到你在/usr/local工作-也许它正在从/usr中挑选一个较旧的版本。
#2
33
I encountered this problem when I just upgraded from ubuntu 12.10 to 13.04, and I fixed this by copying the /usr/bin/python to /path/to/my/env/bin/, and it worked just fine
当我从ubuntu 12.10升级到13.04时,我遇到了这个问题,我通过复制/usr/bin/python to/ path/到/我/env/bin/,解决了这个问题,而且效果很好。
cp /user/bin/python /path/to/my/env/bin/
cp / user / bin / python /道路/ /我/ env / bin /
or, there's a more elegant way to fix this(reference):
或者,有一种更优雅的方法来解决这个问题(参考):
mkvirtualenv <existing virtualenv name>
mkvirtualenv <现有virtualenv名称>
#3
2
If all else fails, I got things running using this: http://www.kiwisoft.co.uk/blog/2014/08/17/fixed-importerror-cannot-import-name-maxrepeat
如果其他方法都失败了,我可以使用以下方法运行:http://www.kiwisoft.co.uk/blog/2014/08/17/unporterror- cannon -name-maxrepeat。
#4
1
I had the same problem recently. Setting LD_LIBRARY_PATH= solved the problem.
我最近遇到了同样的问题。设置LD_LIBRARY_PATH=解决了问题。
#5
1
I was using cx_freeze 4.3.2 on my win 8 machine and it was always showing ImportError: cannot import name MAXREPEAT with cx Freeze
if I ever tried to freeze a non built-in module, and once I downloaded version 4.3.1, it works, I'm able to freeze my all python 3.3 programs without any problem now.
我使用cx_freeze 4.3.2赢得8机和它总是显示ImportError:不能导入名称MAXREPEAT残雪冻结如果我试过冻结非内置模块,一旦我下载版本4.3.1,它的工作原理,能够冻结我所有python 3.3程序现在没有任何问题。
#6
0
I was having similar issues on windows 8 - was just a PYTHONPATH issue. check that PYTHONPATH exists by typing the following into a python session:
我在windows 8上也遇到过类似的问题——只是一个PYTHONPATH的问题。通过在python会话中输入以下内容来检查是否存在PYTHONPATH:
import os
进口操作系统
os.environ['PYTHONPATH'].split(os.pathsep)
os.environ[' PYTHONPATH '].split(os.pathsep)
if you get an error set your PYTHONPATH using this approach..
如果您得到一个错误,请使用此方法设置您的PYTHONPATH。
How to add to the pythonpath in windows 7?
如何在windows 7中添加pythonpath ?
#1
14
_sre
is a built in module, so there's no file to include for it, but it doesn't have a MAXREPEAT attribute in Python 2.7.3:
_sre是在模块中构建的,所以没有包含它的文件,但是它在Python 2.7.3中没有MAXREPEAT属性:
>>> import _sre
>>> _sre
<module '_sre' (built-in)>
>>> _sre.MAXREPEAT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'MAXREPEAT'
My best guess is that your frozen copy somehow has the standard library .py modules from Python 2.7.4, but the compiled Python interpreter from 2.7.3 or an earlier version. I see you're working from /usr/local
- maybe it's picking up an older version from /usr
.
我最好的猜测是,您的frozen copy某种程度上拥有来自Python 2.7.4的标准库.py模块,但是编译过的Python解释器来自2.7.3或更早的版本。我看到你在/usr/local工作-也许它正在从/usr中挑选一个较旧的版本。
#2
33
I encountered this problem when I just upgraded from ubuntu 12.10 to 13.04, and I fixed this by copying the /usr/bin/python to /path/to/my/env/bin/, and it worked just fine
当我从ubuntu 12.10升级到13.04时,我遇到了这个问题,我通过复制/usr/bin/python to/ path/到/我/env/bin/,解决了这个问题,而且效果很好。
cp /user/bin/python /path/to/my/env/bin/
cp / user / bin / python /道路/ /我/ env / bin /
or, there's a more elegant way to fix this(reference):
或者,有一种更优雅的方法来解决这个问题(参考):
mkvirtualenv <existing virtualenv name>
mkvirtualenv <现有virtualenv名称>
#3
2
If all else fails, I got things running using this: http://www.kiwisoft.co.uk/blog/2014/08/17/fixed-importerror-cannot-import-name-maxrepeat
如果其他方法都失败了,我可以使用以下方法运行:http://www.kiwisoft.co.uk/blog/2014/08/17/unporterror- cannon -name-maxrepeat。
#4
1
I had the same problem recently. Setting LD_LIBRARY_PATH= solved the problem.
我最近遇到了同样的问题。设置LD_LIBRARY_PATH=解决了问题。
#5
1
I was using cx_freeze 4.3.2 on my win 8 machine and it was always showing ImportError: cannot import name MAXREPEAT with cx Freeze
if I ever tried to freeze a non built-in module, and once I downloaded version 4.3.1, it works, I'm able to freeze my all python 3.3 programs without any problem now.
我使用cx_freeze 4.3.2赢得8机和它总是显示ImportError:不能导入名称MAXREPEAT残雪冻结如果我试过冻结非内置模块,一旦我下载版本4.3.1,它的工作原理,能够冻结我所有python 3.3程序现在没有任何问题。
#6
0
I was having similar issues on windows 8 - was just a PYTHONPATH issue. check that PYTHONPATH exists by typing the following into a python session:
我在windows 8上也遇到过类似的问题——只是一个PYTHONPATH的问题。通过在python会话中输入以下内容来检查是否存在PYTHONPATH:
import os
进口操作系统
os.environ['PYTHONPATH'].split(os.pathsep)
os.environ[' PYTHONPATH '].split(os.pathsep)
if you get an error set your PYTHONPATH using this approach..
如果您得到一个错误,请使用此方法设置您的PYTHONPATH。
How to add to the pythonpath in windows 7?
如何在windows 7中添加pythonpath ?