ImportError when running dev_appserver.py from pycharm

点点圈 提交于 2019-12-13 13:18:56

问题


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: 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).


回答1:


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.




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/51568417/importerror-when-running-dev-appserver-py-from-pycharm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!