Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named warnings when starting GAE inside virtualenv locally

I am trying to run my GAE app locally inside a virtual environment.

I've followed these two articles [1], [2] as reference to setup, but when I source evn/bin/activate and then dev_appserver.py ., it keeps raising the error of ImportError: No module named warnings (more trace below)

Surprisingly, if I start it without activating virtual env by just running dev_appserver.py . inside root of project it runs without any issue.

Is there any solution or workaround for this problem?

INFO     2017-08-31 14:09:36,293 devappserver2.py:116] Skipping SDK update check.
INFO     2017-08-31 14:09:36,354 api_server.py:313] Starting API server at: http://localhost:52608
INFO     2017-08-31 14:09:36,357 dispatcher.py:226] Starting module "default" running at: http://localhost:8080
INFO     2017-08-31 14:09:36,359 admin_server.py:116] Starting admin server at: http://localhost:8000
Traceback (most recent call last):
  File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 103, in <module>
    _run_file(__file__, globals())
  File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 97, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime.py", line 192, in <module>
    main()
  File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime.py", line 172, in main
    sandbox.enable_sandbox(config)
  File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 326, in enable_sandbox
    __import__('%s.threading' % dist27.__name__)
  File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/dist27/threading.py", line 11, in <module>
    import warnings
  File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 1076, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named warnings
ERROR    2017-08-31 14:09:39,070 instance.py:280] Cannot connect to the instance on localhost:52366
like image 643
R‌‌‌.. Avatar asked Aug 31 '17 14:08

R‌‌‌..


2 Answers

I've solved it by removing from the skip_files of my .yaml a - venv line. venv is my virtualenv folder, and I still have a - ^venv$ line. In case that helps someone ;-)

like image 158
Valentin Coudert Avatar answered Oct 18 '22 00:10

Valentin Coudert


All dependencies for standard environment GAE apps (which aren't provided by GAE) must be installed in the app itself, not on your local system. See Using third-party libraries.

Since GAE doesn't care about your local system libraries (besides the basic python 2.7 installation needed to run the development server), using a virtualenv for developing standard env GAE apps doesn't make a lot of sense.

The use of the virtualenv as suggested by the articles you mentioned can actually cause trouble:

  • local python libraries can interfere with the GAE runtime-provided equivalent libraries (from the SDK) when running locally (I suspect this is somehow what you're experiencing)
  • at deployment time the content of the lib directory (which includes all the site packages for your python installation) will be uploaded to GAE, potentially causing clashes with the GAE runtime-provided libraries or exceeding the app file quota.

So my suggestion is to drop virtualenv (which, in a way, you did when you skipped the virtualenv activation) and follow the official documentation instead.

like image 4
Dan Cornilescu Avatar answered Oct 18 '22 01:10

Dan Cornilescu