ImportError when running dev_appserver.py from pycharm
Asked Answered
C

4

4

I'm using the latest version of pycharm 2018.2, on Windows. I've also updated the Google Cloud Sdk to the latest versions too.

When I use the built in App Engine run configuration in Pycharm: enter image description here I get an import error ImportError: cannot import name _common appearing in the run window:

"C:\Program Files\JetBrains\PyCharm 2018.1.1\bin\runnerw.exe" C:\Code\my- 
 project\env\Scripts\python.exe "C:/Program Files (x86)/Google/Cloud 
 SDK/google-cloud-sdk/bin/dev_appserver.py" --port 8484 app.yaml tasks.yaml 
 longtasks.yaml --log_level=debug Traceback (most recent call last):
 File "C:/Program Files (x86)/Google/Cloud SDK/google-cloud- 
 sdk/bin/dev_appserver.py", line 12, in <module>
   from bootstrapping import bootstrapping
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-   
   sdk\bin\bootstrapping\bootstrapping.py", line 24, in <module>
  from . import setup  # pylint:disable=g-import-not-at-top
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud- 
  sdk\bin\bootstrapping\setup.py", line 55, in <module>
  from googlecloudsdk.core import properties
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud- 
  sdk\lib\googlecloudsdk\core\properties.py", line 36, in <module>
  from googlecloudsdk.core.util import times
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud- 
  sdk\lib\googlecloudsdk\core\util\times.py", line 55, in <module>
  from dateutil.tz import _common as tz_common
  ImportError: cannot import name _common

  Process finished with exit code 1

The dateutil.tz package is located in C:\Python27\Lib\site-packages and I have a dateutil package in the project I'm running. I don't know whether that has something to do with the issue. I've tried changing the default python interpreter which also did not work. I've tried running Pycharm as administrator which also had no effect. Both the debug and non-debug run commands result in this issue.

If I run the command to start up dev_appserver.py directly in the terminal (with or without virtual environment python), it works correctly e.g. "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/dev_appserver.py" --port 8484 app.yaml tasks.yaml longtasks.yaml

Also, if I run the command that pycharm is running (except for the runnerw part), then it works correctly (from command line) too:

C:\Code\project>C:\Code\project\env\Scripts\python.exe "C:/Program Files 
(x86)/Google/Cloud SDK/google-cloud-sdk/bin/dev_appserver.py" --port 8484 
 app.yaml tasks.yaml longtasks.yaml --log_level=debug
 INFO     2018-07-29 08:11:15,566 devappserver2.py:178] Skipping SDK update 
 check.
 INFO     2018-07-29 08:11:17,726 api_server.py:274] Starting API server at: 
 http://localhost:59886
 INFO     2018-07-29 08:11:18,259 dispatcher.py:270] Starting module 
   "default" running at: http://localhost:8484
 INFO     2018-07-29 08:11:18,519 dispatcher.py:270] Starting module "tasks" 
 running at: http://localhost:8485
 INFO     2018-07-29 08:11:18,815 dispatcher.py:270] Starting module 
"longtasks" running at: http://localhost:8486
INFO     2018-07-29 08:11:18,822 admin_server.py:152] Starting admin server 
at: http://localhost:8000

It's also worth noting that I can run other GAE projects in Pycharm and they do run (which leads me to think it's something to do with my configuration of this project).

Carabiniere answered 28/7, 2018 at 5:39 Comment(8)
What command do you use to "start up dev_appserver.py directly in the terminal"?Abrams
Note that pycharm runs your program a bit differently that the cmd you tried manually (you have the exact cmd logged): C:\Code\my-project\env\Scripts\python.exe "C:.../dev_appserver.py" .... Try that manually. Is your project configured to use a virtualenv? (note the non-standard python.exe used)Coppola
@sraw "C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/dev_appserver.py" --port 8484 app.yaml tasks.yaml longtasks.yaml is command I run in terminal.Carabiniere
@DanCornilescu I've updated the question with that output; it works correctly.Carabiniere
Maybe you have a _common symbol already imported?Coppola
@DanCornilescu where would I find this out? Also, would this not be the runnerw.exe (from pycharm) causing this, given that I can run it from command prompt with both the venv python and my default python versions?Carabiniere
Hack the SDK code and put a print type(_common) right above that import, for example. I'm clueless about that runnerw.exe, I'm using linux.Coppola
Did you check that the library is in the path? Check How do I import modules in pycharm? thread for reference.Chimpanzee
M
4

This is a bug in 2018.2.4 of PyCharm Pro. I had the same issue, and rolled back to 2018.1.5 and it worked fine.

The problem is that 2018.2.4 is loading the cloud-sdk appengine flexible environment classes instead of the standard environment classes.

Milissamilissent answered 28/9, 2018 at 19:20 Comment(4)
Any idea on how to fix this? It looks like it still isn't fixed (2019.2 PyCharm Pro EAP)Tiphane
On OS X it definitely still isn't fixed as of May 2019. You have to use a 2018 versionMilissamilissent
FYI:I've figured out that if you run it with dev_appserver.py script, you can run it in debug mode. It works the sameTiphane
you are right, if you just run a python app with /Users/[your username]/google-cloud-sdk/platform/google_appengine/dev_appserver.py as the script it runs. The problem is pycharm is trying to run google-cloud-sdk/bin/dev_appserver.pyMilissamilissent
E
1

A hacky way to overcome this is to open <path-to...>/googlecloudsdk/core/util/times.py in a text editor and comment out

from dateutil.tz import _common as tz_common

and

tz_common.PY3 = True  # MONKEYPATCH!!! Fixes a Python 2 standard module bug.

Assuming you don't need this "monkeypatch", this solves the issue.

Ejection answered 19/9, 2019 at 10:57 Comment(0)
P
0

I installed version 211.0.0 - https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-211.0.0-darwin-x86_64.tar.gz

Followed by:

gcloud components install app-engine-python
Phonemic answered 25/3, 2019 at 13:58 Comment(0)
S
0

@user2061291's comments it's true. Pycharm is trying to run google-cloud-sdk/bin/dev_appserver.py. If you want to run app engine from pycharm anyway because you want to debug your code or something else then you should create a new python runner like this:

Script path:

/{YOUR GOOGLE-CLOUD-SDK ROOT PATH}/google-cloud-sdk/platform/google_appengine/dev_appserver.py

For example:

Spar answered 24/3, 2020 at 20:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.