7

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
‌‌R‌‌‌.
  • 2,818
  • 26
  • 37

3 Answers3

19

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 ;-)

Valentin Coudert
  • 1,759
  • 3
  • 19
  • 44
  • 1
    Not sure why this doesn't have more votes. In case anybody finds this thread via Google, this is the correct answer. – Edgar Derby May 10 '18 at 21:59
  • 2
    @valentin-coudert solution actually helps but not sure why does this works, I thought skip_files is only used while deploying the application to GAE. Also, does this means we should deploy venv folder along with code to GAE? – vinit payal Jul 10 '18 at 04:22
4

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.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • 2
    I agree with your analysis, however the official documentation says to use a virtualenv! https://cloud.google.com/appengine/docs/standard/python/getting-started/python-standard-env – Mike Vella Dec 02 '17 at 00:11
  • If you use it like that yes. But the articles referenced in the question are not. – Dan Cornilescu Dec 02 '17 at 01:12
  • I'm not sure what you mean. I used it in the way described in the official documentation and got the same problem as the OP. – Mike Vella Dec 02 '17 at 01:14
  • Well, try without it. IMHO it's just an extra layer to debug. The only reason for which I'd use it would be if my default python version wouldn't be the one needed for GAE. But in my case it's not. In the OP's case - running the same app without virtualenv appeared to work better. – Dan Cornilescu Dec 02 '17 at 01:20
  • 2
    The official documentation is wrong in my opinion. I don't know how such a mistake was made but at least on OSX if you follow it you will get the same problem as OP. – Mike Vella Dec 02 '17 at 01:22
  • Another thought: I'm unusure if pip produces the same results reliably - pypy packages are updated now and then. Something may have changed since the doc was written. Unrelated to virtualenv. – Dan Cornilescu Dec 02 '17 at 01:23
  • 3
    It's possible. I've given Google feedback on the official docs, will see what happens. Like you I don't really understand the point of using a virtual environment if the dev server pulls all dependencies from the libs directory but perhaps I'm missing something. – Mike Vella Dec 02 '17 at 01:25
1

I had this problem when running two AppEngine projects in separate directories at once using dev_appserver.py in a virtualenv.

I found it works correctly if I use absolute paths instead.

Nick Lothian
  • 1,427
  • 1
  • 15
  • 31