I have the following code in appengine_config.py:
...
import six
print six.__version__
print six.moves
import six.moves
The output is as follows:
1.11.0
<module 'six.moves' (built-in)>
ERROR 2018-04-17 10:51:19,875 wsgi.py:263]
Traceback (most recent call last):
File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 351, in __get
attr__
self._update_configs()
File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 287, in _update_configs
self._registry.initialize()
File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 160, in initi
alize
import_func(self._modname)
File "/home/user/project/appengine_config.py", line 17, in <module>
from six.moves import http_client
ImportError: No module named moves
How is it possible that moves is a module when accessed through six, but can't be imported on its own?
To give some context about the environment:
I use a clean Debian GCE VM.
Install python 2.7, virtualenv, from within virtualenv install a short list of basic dependencies.
The script is run from within dev_appserver.py (Google App Engine standard environment local dev server)
six.moves imports fine from python shell
You've already imported six. That includes six.moves. So just use it as six.moves. To import just moves, use:
from six import moves
Related
So, I created a small flask API. Basically a wrapper for another API.
I used requests-futures to send multiple calls asynchronously.
I set up my virtual environment. Everything works exactly as I intend. However, when I try to run some tests I've written (using python -m unittest) this is the error I get:
======================================================================
ERROR: test (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test
Traceback (most recent call last):
File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/home/cwverica/take-home-apps/quixr/test.py", line 2, in <module>
from app import app, session
File "/home/cwverica/take-home-apps/quixr/app.py", line 3, in <module>
from requests_futures.sessions import FuturesSession
ModuleNotFoundError: No module named 'requests_futures'
I have reinstalled the module using pip. I made sure to pip freeze > requirements.txt just in case it was reading module availability from there. But all in all I'm stumped. If anyone could help me out here, I'd greatly appreciate it.
I want to create get client lib java and when i run this code
sudo python lib/endpoints/endpointscfg.py get_client_lib java -bs gradle src.service.moDbile_api.MobileApi
it gave me an error
valid SDK root.
Traceback (most recent call last):
File "lib/endpoints/endpointscfg.py", line 59, in <module>
import _endpointscfg_setup # pylint: disable=unused-import
File "/var/www/html/salesmanagement/SalesManagement/lib/endpoints/_endpointscfg_setup.py", line 107, in <module>
_SetupPaths()
File "/var/www/html/salesmanagement/SalesManagement/lib/endpoints/_endpointscfg_setup.py", line 103, in _SetupPaths
from google.appengine.ext import vendor
ImportError: No module named appengine.ext
The google.appengine.ext module only exists when running your script in the App Engine First Generation (Python 2.7) runtime.
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'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?
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?