I'm running into an issue with cx_Freeze when running a frozen application (works fine 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.
This is usually down to cx_Freeze not pulling everything into library.zip and can be fixed by explicitly naming the module in cx_Freezes setup include list and is the solution to this similar question, but that hasn't helped here.
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.
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.
>>> 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.
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.
...
# /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
...
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
cp /user/bin/python /path/to/my/env/bin/
or, there's a more elegant way to fix this(reference):
mkvirtualenv <existing virtualenv name>
_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:
>>> 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.
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
I had the same problem recently. Setting LD_LIBRARY_PATH=
solved the problem.
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.
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:
import os
os.environ['PYTHONPATH'].split(os.pathsep)
if you get an error set your PYTHONPATH using this approach..
How to add to the pythonpath in windows 7?
Related
I've started playing around with pygame and pythonw recently, however whenever I attempt to import a majority of modules pythonw either imports incomplete modules or fails to import entirely.
All of the importing errors involve a Expected in: Flat Namespace
error with one of the many .so files in my conda3 python directory, which led me to believe that they were being loaded incorrectly by python or that they were broken; however, the modules all imported correctly in regular python.
I've ruled out the pythonw being located in a directory with nonexistent modules, as running sys.path in python and pythonw returns the same list.
Example of error, with the default-loaded help() command in Python(w) idle:
>>> help()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda3/lib/python3.6/_sitebuiltins.py", line 102, in __call__
import pydoc
File "/anaconda3/lib/python3.6/pydoc.py", line 63, in <module>
import platform
File "/anaconda3/lib/python3.6/platform.py", line 116, in <module>
import sys, os, re, subprocess
File "/anaconda3/lib/python3.6/subprocess.py", line 136, in <module>
import _posixsubprocess
ImportError: dlopen(/anaconda3/lib/python3.6/lib-dynload/_posixsubprocess.cpython-36m-darwin.so, 2): Symbol not found: __Py_set_inheritable_async_safe
Expected in: flat namespace
Referenced from: /anaconda3/lib/python3.6/lib-dynload/_posixsubprocess.cpython-36m-darwin.so
In the case of pygame, modules such as font are loaded incorrectly and instead replaced with pygame.MissingModule objects
>>> pygame
<module 'pygame' from '/anaconda3/lib/python3.6/site-packages/pygame/__init__.py'>
>>> pygame.font
<pygame.MissingModule object at 0x10e8b5400>
>>>
Does anyone have any idea what is happening here? Any help would be greatly appreciated!
EDIT: [1]: https://i.stack.imgur.com/jDBrB.jpg
I have multiple Python versions installed with pyenv on Ubuntu 16.04. I create virtual environments to work with projects using different versions with pipenv. However, for Python 3.5.x only I get errors like this when I try to edit a file with Vim 8 (installed via the PPA) in an activated virtualenv:
"test.py" 49L, 1434C
Error detected while processing function jedi#init_python[4]..<SNR>48_init_python[27]..jedi#setup_python_imports:
line 25:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/user/.local/share/virtualenvs/test-AYf6DmHL/lib/python3.5/imp.py", line 19, in <module>
from importlib._bootstrap import _ERR_MSG, _exec, _load, _builtin_from_name
File "/home/user/.local/share/virtualenvs/test-AYf6DmHL/lib/python3.5/importlib/__init__.py", line 57, in <module>
import types
File "/home/user/.local/share/virtualenvs/test-AYf6DmHL/lib/python3.5/types.py", line 166, in <module>
import functools as _functools
File "/home/user/.local/share/virtualenvs/test-AYf6DmHL/lib/python3.5/functools.py", line 23, in <module>
from weakref import WeakKeyDictionary
File "/home/user/.local/share/virtualenvs/test-AYf6DmHL/lib/python3.5/weakref.py", line 12, in <module>
from _weakref import (
ImportError: cannot import name '_remove_dead_weakref'
The issue seems to affect all python related Vim plugins. With other Python versions (e.g. 3.6.x, 3.7.x) this does not occur. What may be causing this issue?
Update: It seems that when I run Vim inside a 3.5.x virtualenv, the Vim's interpreter's sys.path gets updated somehow. For example, this is the output of :py3 import sys; print(sys.path) inside a 3.6.0 virtualenv:
['/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5
/dist-packages', '/usr/lib/python3/dist-packages', '_vim_path_']
And this is for 3.5.3:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/testuser/.local/share/virtualenvs/venv-3.5-8feRiT5s/lib/python3.5/imp.py", line 19, in <module>
from importlib._bootstrap import _ERR_MSG, _exec, _load, _builtin_from_name
File "/home/testuser/.local/share/virtualenvs/venv-3.5-8feRiT5s/lib/python3.5/importlib/__init__.py", line 57, in <module>
import types
File "/home/testuser/.local/share/virtualenvs/venv-3.5-8feRiT5s/lib/python3.5/types.py", line 166, in <module>
import functools as _functools
File "/home/testuser/.local/share/virtualenvs/venv-3.5-8feRiT5s/lib/python3.5/functools.py", line 23, in <module>
from weakref import WeakKeyDictionary
File "/home/testuser/.local/share/virtualenvs/venv-3.5-8feRiT5s/lib/python3.5/weakref.py", line 12, in <module>
from _weakref import (
ImportError: cannot import name '_remove_dead_weakref'
['/must>not&exist', '/home/testuser/.local/share/virtualenvs/venv-3.5-8feRiT5s/lib/python35.zip', '/home/testuser/.local/share/virtualenvs/venv-3.5-8feRiT5s/li
b/python3.5', '/home/testuser/.local/share/virtualenvs/venv-3.5-8feRiT5s/lib/python3.5/plat-x86_64-linux-gnu', '/home/testuser/.local/share/virtualenvs/venv-3.
5-8feRiT5s/lib/python3.5/lib-dynload', '/home/testuser/.pyenv/versions/3.5.7/lib/python3.5', '/home/testuser/.local/share/virtualenvs/venv-3.5-8feRiT5s/lib/pyt
hon3.5/site-packages']
The issue can be reproduced in a ubuntu:16.04 docker container.
Debian Bug report logs - #852163: python3.5-minimal wont configure demonstrates that this error (for Python 3.5 and Python 3.6) is due to another incompatible installation of Python in /usr/local.
Some further digging with another user in #debian who was experiencing this
problem indicated that it was related to a locally installed
/usr/local/bin/python3.5. The stdlib in /usr/lib/python3.5 is picked up by the
/usr/local/bin/python3.5 but is not compatible with it, resulting in the
stacktrace shown.
Removing /usr/local/bin/python3* and all traces of that installation from
/usr/local/lib (plus other associated tools) solved this problem for the user
I was helping in #debian.
-- Stuart Prescott (link)
The problem is caused by the system installed python, which conflicts with personally installed python.
It could be the case that other python versions are interfering here. Do you have a PYTHONPATH set?
echo $PYTHONPATH
If it is set you could try to unset it. It's usually not needed when using virtual environments.
Try running python with sudo. I think the python which comes with OS needs to run with admin privilege.
I want to use regex package without installation (neither using pip nor python setup.py install)
For that, I have downloaded the package and kept in the same directory of the file where I am importing regex. The code is given below
import sys
import os
currentdirectory = os.getcwd()
sys.path.append(currentdirectory+"/packages/regex/Python2/")
from regex import *
I am getting following error as _regex extension module is not created.
Traceback (most recent call last):
File "test.py", line 30, in <module>
from regex import *
File "/Users/nilakshi/test_branch/packages/regex/Python2/regex.py", line 387, in <module>
import _regex_core
File "/Users/nilakshi/test_branch/packages/regex/Python2/_regex_core.py", line 21, in <module>
import _regex
ImportError: No module named _regex
How do I create _regex extension module that can be locally used?
Also, can I create _regex extension module file such that I can use the same file in different machines without creating again?
I'm running into an issue with cx_Freeze when running a frozen application (works fine 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.
This is usually down to cx_Freeze not pulling everything into library.zip and can be fixed by explicitly naming the module in cx_Freezes setup include list and is the solution to this similar question, but that hasn't helped here.
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.
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.
>>> 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.
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.
...
# /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
...
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
cp /user/bin/python /path/to/my/env/bin/
or, there's a more elegant way to fix this(reference):
mkvirtualenv <existing virtualenv name>
_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:
>>> 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.
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
I had the same problem recently. Setting LD_LIBRARY_PATH=
solved the problem.
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.
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:
import os
os.environ['PYTHONPATH'].split(os.pathsep)
if you get an error set your PYTHONPATH using this approach..
How to add to the pythonpath in windows 7?
Maybe someone has a clue about this one. Google, the Logilab.org archives and every other source I tried to determine a solution have turned up empty.
I was trying to get Pylint 2.4 running with PyDev in Eclipse (with Python 2.6) on Windows, but right now I'd be happy simply running pylin at all. I used easy_install to install pylint and it's dependancies. That seemed to work fine. However if I try to run c:\python26\Scripts\pylint.bat , I get the following:
Traceback (most recent call last):
File "C:\Python26\Scripts\pylint", line 5, in <module>
pkg_resources.run_script('pylint==0.24.0', 'pylint')
File "c:\Python26\lib\site-packages\pkg_resources.py", line 489, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "c:\Python26\lib\site-packages\pkg_resources.py", line 1207, in run_script
execfile(script_filename, namespace, namespace)
File "c:\python26\lib\site-packages\pylint-0.24.0-py2.6.egg\EGGINFO\scripts\pylint", line 3, in <module>
from pylint import lint
File "c:\Python26\lib\site-packages\pylint-0.24.0-py2.6.egg\pylint\lint.py", line 31, in <module>
from pylint.checkers import utils
File "c:\Python26\lib\site-packages\pylint-0.24.0py2.6.egg\pylint\checkers\__init__.py", line 44, in <module>
from logilab.astng.utils import ASTWalker
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0py2.6.egg\logilab\astng\__init__.py", line 58, in <module>
from logilab.astng.nodes import *
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0-py2.6.egg\logilab\astng\nodes.py", line 54, in <module>
from logilab.astng.node_classes import Arguments, AssAttr, Assert, Assign, \
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0-py2.6.egg\logilab\astng\node_classes.py", line 27, in <module>
from logilab.astng.bases import (NodeNG, Statement, Instance, InferenceContext,
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0-py2.6.egg\logilab\astng\bases.py", line 28, in <module>
from logilab.common.compat import builtins
ImportError: cannot import name builtins
I mucked around and looked into based.py, but I have no clue what the problem is. My shell path includes C:\python26;c:\Python26\Scripts.
Does this have something to do with lib2to3? Or Python 2.6 compatibility?
Note that I installed pylint using "easy_install pylint", and logilab-common is at the latest 0.56.2.
Thanks!
For me, there is a logilab.common.compat module buried inside the egg "logilab.pylintinstaller-0.15.2-py2.6.egg" in my site-packages folder. Having the logilab_common egg installed, removing the pylintinstaller egg got pylint working in eclipse. I found this out via IPython like so:
In [37]: import logilab.common.compat
In [38]: from logilab.common.compat import builtins
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
C:\Users\Rio\Documents\mcedit\pymclevel\<ipython console> in <module>()
ImportError: cannot import name builtins
In [41]: logilab.common.compat.__file__
Out[41]: 'c:\\python26\\lib\\site-packages\\logilab.pylintinstaller-0.15.2-py2.6.egg\\logilab\\common\\compat.pyc'
Probably you don't have the logilab.common package or the installed version is an old one.
try:
easy_install-2.6 --upgrade logilab-common