Pycharm issue - ImportError: No module named appengine.datastore.datastore_query

I have been trying to use the excellent project located at http://docs.gae-init.appspot.com/, in order to learn python, GAE and perhaps start my own hobby project. My IDE is Pycharm 3.4 Professional Edition. Operating system is OSX Mavericks.

I have been trying to follow the tutorial, therefore I have git cloned the project at a local directory and subsequently opened in into Pycharm. I believe I have managed to resolve the majority of requirements (PyCharm helps a lot).

Nevertheless, when trying to Run the project I get the following error:

  File "/Users/nilminus/Developer/phonebook/main/main.py", line 9, in <module>
    import util
  File "/Users/nilminus/Developer/phonebook/main/util.py", line 10, in <module>
    from google.appengine.datastore.datastore_query import Cursor
ImportError: No module named appengine.datastore.datastore_query

I have configured GAE directory as /usr/local/google_appengine which is correct. Pycharm does not complain about not finding this module before actually executing it. There is a warning that module google is not listed in requirements.txt, but it does not makes sense to me that this could be the issue.

I have included PYTHONPATH in .profile and ~/.bash_profile: PYTHONPATH=/usr/local/google_appengine/:/usr/local/google_appengine/lib/:/usr/local/google_appengine/lib/yaml/

The funny thing is that if I upload this exact project in GAE, it works perfectly. Also, if I run this project with ./run.py -s (as exhibited by its author), it works again. Even ./dev_appserver.py main/ works.

This issue has truely dazzled me that last week. Any help is highly appreciated.
6 comments
Comment actions Permalink
Have you tried setting up an App Engine type project and importing the code into that?  Otherwise it may not find the GAE SDK.  Have you looked at this: http://www.jetbrains.com/pycharm/quickstart/appengine_guide.html
0
Comment actions Permalink
I haven't found a guide explaining what you just said, meanining: setup new project, import the code.
What I have been doing so far is "Open directory" in the wizard and enable GAE support.
Is there a way to create or import project from existing source code?

A colleague suggested that I can create a blank GAE project and copy the .idea directory into my project. This seems to work but does not sound like the proper way to do this.
0
Comment actions Permalink
What I have been doing so far is "Open directory" in the wizard and enable GAE support.


As far as I know that should work, assuming you set the correct SDK location for GAE. Once you have done that, look at the Project Interpreter in Settings. Does it not show the google packages there?

Is there a way to create or import project from existing source code?


Sure, just create a new project and then copy in the code (e.g. on the command line or Finder). If the code you want is in a VCS repo, you can go to the VCS menu in PyCharm and do a checkout after you already created the project.  Just check out the code to the appropriate directory.

A colleague suggested that I can create a blank GAE project and copy the .idea directory into my project. This seems to work but does not sound like the proper way to do this.


I don't really see a problem with that, but if you find it too icky, you should be able to either import your code into a new GAE project, or possibly just enable GAE support on your existing checkout/project.
0
Comment actions Permalink
Also, are you creating an actual GAE Run Configuration, or a generic Python one?
0
Comment actions Permalink
I am not sure I understand your last question.
When i start a brand new project, I choose a GAE project in the wizard.

From what I understand is that the difference between python and GAE projects is that you have to enable GAE support in Pycharm project preferences.
0
Comment actions Permalink
If you create a brand new GAE type project it creates a GAE Run Configuration for you automatically. If you started with a non-GAE project you can still create a new GAE run config after enabling GAE in the project preferences.

A run configuration is how PyCharm knows what to do when you click Run or Debug and you can have more than one.  Click on the Run menu -> Edit Configurations. To run a local development GAE server you must use a run config defined as type "App Engine server".

To create one click the little green plus icon and select App Engine server. After you close the dialog make sure that GAE run config is selected in the current run config dropdown in the toolbar, then you can run it. The icon looks like the GAE icon instead of the Python one.
0

Please sign in to leave a comment.