Import error when using dev_appserver.py in virtualenv

When I run dev_appserver.py . (in the directory containing app.py ), being in virtualenv with Python 2.7.12, I get this error and output:

 (.venv)$ dev_appserver.py . INFO 2017-02-21 18:54:47,250 devappserver2.py:764] Skipping SDK update check. INFO 2017-02-21 18:54:47,273 api_server.py:268] Starting API server at: http://localhost:35473 INFO 2017-02-21 18:54:47,276 dispatcher.py:199] Starting module "default" running at: http://localhost:8080 INFO 2017-02-21 18:54:47,276 admin_server.py:116] Starting admin server at: http://localhost:8000 Traceback (most recent call last): File "/opt/gcloud/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 101, in <module> _run_file(__file__, globals()) File "/opt/gcloud/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 97, in _run_file execfile(_PATHS.script_file(script_name), globals_) File "/opt/gcloud/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime.py", line 185, in <module> main() File "/opt/gcloud/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime.py", line 165, in main sandbox.enable_sandbox(config) File "/opt/gcloud/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 198, in enable_sandbox __import__('%s.threading' % dist27.__name__) File "/opt/gcloud/google-cloud-sdk/platform/google_appengine/google/appengine/dist27/threading.py", line 11, in <module> import warnings File "/opt/gcloud/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 1001, in load_module raise ImportError('No module named %s' % fullname) ImportError: No module named warnings 

Works great when I'm not in virtualenv. The warnings module is part of the python standard library, as I understand it, so I'm not sure what to do here. Running pip install warnings does not help.

How to get dev_appserver.py to run in virtualenv?

+5
source share
1 answer

I did not work with dev_appserver.py and virtualenv correctly. Virtualenv cannot be used here. The relevant documentation for using third-party libraries is here .


In short, to enable third-party libraries with dev_appserver.py:

Instruct pip to store the libraries in the folder with the -t flag:

 $ pip install -t lib/ <library name> 

Create a file called appengine_config.py in the same folder as the app , and include the following code:

 from google.appengine.ext import vendor # Add any libraries install in the "lib" folder. vendor.add('lib') 

Now run dev_appserver.py as usual: $ dev_appserver.py app.yaml


Keep in mind that you can only use Python libraries that use pure Python code (for example, the bcrypt library cannot be used.).

+4
source

Source: https://habr.com/ru/post/1264535/


All Articles