ImportError when running dev_appserver.py from pycharm

Answered

I've posted this here: https://stackoverflow.com/questions/51568417/importerror-when-running-dev-appserver-py-from-pycharm

 

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

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
7 comments
I have a dateutil package in the project I'm running

This can be a problem indeed. The same named project can cause a collision in PYTHONPATH. Could you please disable

  • Add content roots to PYTHONPATH
  • Add source roots to PYTHONPATH

options in the run configuration? Has it helped?

0

Hi, Thanks for your response.

I disabled and restarted+invalidated caches. Still no joy.

Changed python interpreter, also didn't work.

If I run the command (excluding the runnerw.exe portion) that pycharm runs, then it works (in the command window only).

e.g. 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

 

 

Thanks

Rob

 

 

0

@Pavel Karateev do you have any further advice I could use to resolve this?

I'm currently resorting to running this from the command line, but I really like the integrated experience (especially debugging). Please let me know, thanks

Rob

0

same problem here on the mac:

 

/Users/xxxxxx/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

 

This happened after upgrading to 2018.2.4

What executable dev_appserver.py does pycharm go after?  there are 2:  1 in /google-cloud-sdk/bin and 1 in /google-cloud-sdk/platform/google_appengine

0

I am sorry for the late response. Unfortunately, I had no luck reproducing the problem. Could you please specify which Python version you are using? Could you please go to

google-cloud-sdk\lib\googlecloudsdk\core\util\times.py


and add

import datetime.tz
print(datetime.tz)


at the beginning of the file? And check the output in both PyCharm and in the terminal?

2

I believe this is a bug in 2018.2.4.   For me, I re-installed 2018.1.5 and it worked fine on the Mac.   Other people in our org find 2018.2.4 works fine on Ubuntu

I also talked to a contact at Google.  The problem is that it is loading the App Engine flexible classes instead of the appengine python files.  Appengine Standard does not depend on the classes in googlecloudsdk/core/util/

0

@steve @pavel, thanks.

 

@Pavel Karateev,I assume you mean dateutil.tz

In pycharm, the output is: <module 'dateutil.tz' from 'C:\Python27\lib\site-packages\dateutil\tz\__init__.pyc'>

From terminal the output is: <module 'dateutil.tz' from 'C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\dateutil\tz\__init__.pyc'>

 

I've now deleted the dateutil pacakge in "global" site-packages, which now allows me to run appengine in pycharm.

 

Thanks

Rob

0

Please sign in to leave a comment.