2

I'm using pycharm to develop appengine. Now i'm trying to use endpoints and I've put

libraries:
- name: pycrypto
  version: latest
- name: endpoints
  version: 1.0

and then in main.py

import endpoints

But it gives me error

No module named endpoints

I can see the endpoints folder inside the GAE library. Anyone can help?

*EDIT: it is just a matter of IDE (pycharm) cant locate endpoints. The app runs fine and okay both in dev server or cloud server. There is a picture just to make it a bit clearer:

Pycharm cant find endpoints reference

Thanks

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
andiwin
  • 1,552
  • 3
  • 14
  • 27
  • Are you using Managed VMs? – saiyr Jan 19 '16 at 17:49
  • I think I'm just using a normal one not the managed VM – andiwin Jan 19 '16 at 22:50
  • If you can edit your question with the full error, whether or not it's broken on dev server or when you deploy, that might be helpful. If you think it is a bug, you should [file an issue](https://code.google.com/p/googleappengine/issues/list?can=2&q=Component=Endpoints&sort=-modified+-id&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log%20Modified). If you are using Managed VMs (vm: true in app.yaml) then Endpoints is not supported on Managed VMs. – saiyr Jan 20 '16 at 00:33
  • The app runs fine both in dev server or in cloud, it's just the matter of the IDE (which is pycharm) can't detect and find `import endpoints` which just means harder for me to debug and autocomplete some syntax – andiwin Jan 20 '16 at 01:43
  • Ah, apologies, I misread your question. Pycharm has a way to add libraries. If it picks up GAE libraries, that's news to me, but I would manually add it to your path. – saiyr Jan 20 '16 at 01:55
  • Yeah i've added the GAE_SDK path to the library (you can see from the image i can `import google.appengine` or `protorpc`) but for some reason it is just not working for endpoints, even though I clearly see the folder and __init__.py inside it – andiwin Jan 20 '16 at 04:15

3 Answers3

2

You need to add {GAE_SDK}/lib/endpoints-1.0, not just the SDK itself. The reason you can import google is because it is directly under {GAE_SDK}. The libraries you specify in app.yaml are laid out differently due to supporting multiple versions. I believe you also need to add {GAE_SDK}/lib/protorpc-1.0/, it's just not showing because there's already an import error.

saiyr
  • 2,575
  • 1
  • 11
  • 13
  • That fixes it! Thanks a lot, but as for the protorpc, I don't need to add `{GAE_SDK}/lib/protorpc-1.0/` to make it works – andiwin Jan 20 '16 at 22:40
  • There's also the issue of the `google` package existing in the system Python's `site-packages`. A hack involving adding the SDK's `google` location to the imported 'built-in' `google` module's `__path__` makes the packages under `google` available as `google.`. Clear as mud! – Tom Russell Jul 20 '17 at 08:33
  • Here's the incantation that makes that magic happen. Please be sure to tell me if you understand it: `google.__path__.append("{0}/google".format(sdk_path))` – Tom Russell Jul 20 '17 at 08:39
0

I'm using the new version of PyCharm Community and I got to config too. You need to set the Source option on each folder like endpoints in File - Setting - Project:

See my image

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
0

I've run across the following code somewhere which fixes it for me in a client script. I'm not able to say how much of it may be unnecessary. You'd need to edit the google_appengine path for your SDK installation:

sdk_path = os.path.expanduser('~/work/google-cloud-sdk/platform/google_appengine')

try:
    import google
    google.__path__.append("{0}/google".format(sdk_path))
except ImportError:
    pass

try:
    import protorpc
    protorpc.__path__.append("{0}/lib/protorpc-1.0/protorpc".format(sdk_path))
except ImportError:
    pass

sys.path.append("{0}/lib/endpoints-1.0".format(sdk_path))
Tom Russell
  • 1,015
  • 2
  • 10
  • 29