When I run dev_appserver.py .
(in the directory containing the app.py
) while being in an 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 fine when I'm not in the virtualenv. The warnings
module is part of the python standard library as I understand it, so not sure what to to do here. Running pip install warnings
doesn't help.
How do I get dev_appserver.py to run in the virtualenv?
I was not working with dev_appserver.py and virtualenv in a proper way. Virtualenv is not to be used here. Relevant documentation on using third-party libraries is found here.
In short, to include third party libraries with dev_appserver.py:
Instruct pip to store libraries in a folder with the -t
flag:
$ pip install -t lib/ <library name>
Create a file named appengine_config.py
in the same folder as 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 (e.g. the bcrypt
library cannot be used.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With