19

I've started using Eclipe+PyDev as an environment for developing my first app for Google App Engine. Eclipse is configured according to this tutorial.

Everything was working until I start to use memcache. PyDev reports the errors and I don't know how to fix it:

alt text

Error: Undefined variable from import: get

How to fix this? Sure, it is only PyDev checker problem. Code is correct and run on GAE.

UPDATE:

  1. I'm using PyDev 1.5.0 but experienced the same with 1.4.8.
  2. My PYTHONPATH includes (set in Project Properties/PyDev - PYTHONPATH):
    • C:\Program Files\Google\google_appengine
    • C:\Program Files\Google\google_appengine\lib\django
    • C:\Program Files\Google\google_appengine\lib\webob
    • C:\Program Files\Google\google_appengine\lib\yaml\lib

UPDATE 2:

I took a look at C:\Program Files\Google\google_appengine\google\appengine\api\memcache\__init__.py and found get() is not declared as memcache module function. They use the following trick to do that (I didn't hear about such possibility):

_CLIENT = None


def setup_client(client_obj):
  """Sets the Client object instance to use for all module-level methods.

  Use this method if you want to have customer persistent_id() or
  persistent_load() functions associated with your client.

  Args:
    client_obj: Instance of the memcache.Client object.
  """
  global _CLIENT
  var_dict = globals()

  _CLIENT = client_obj
  var_dict['set_servers'] = _CLIENT.set_servers
  var_dict['disconnect_all'] = _CLIENT.disconnect_all
  var_dict['forget_dead_hosts'] = _CLIENT.forget_dead_hosts
  var_dict['debuglog'] = _CLIENT.debuglog
  var_dict['get'] = _CLIENT.get
  var_dict['get_multi'] = _CLIENT.get_multi
  var_dict['set'] = _CLIENT.set
  var_dict['set_multi'] = _CLIENT.set_multi
  var_dict['add'] = _CLIENT.add
  var_dict['add_multi'] = _CLIENT.add_multi
  var_dict['replace'] = _CLIENT.replace
  var_dict['replace_multi'] = _CLIENT.replace_multi
  var_dict['delete'] = _CLIENT.delete
  var_dict['delete_multi'] = _CLIENT.delete_multi
  var_dict['incr'] = _CLIENT.incr
  var_dict['decr'] = _CLIENT.decr
  var_dict['flush_all'] = _CLIENT.flush_all
  var_dict['get_stats'] = _CLIENT.get_stats


setup_client(Client())

Hmm... Any idea how to force PyDev to recognize that?

2
  • Same with 1.4.8? So it should be a PYTHONPATH definition problem then.
    – VonC
    Sep 24, 2009 at 6:41
  • I still got this error with Eclipse Indigo SR2 + PyDev 2.5 (Google App Engine 1.6.6 app) and Python 3.2. weird thing... The solution in my case was to add #@PydevCodeAnalysisIgnore at the top of the page as @Richard Green mentions: stackoverflow.com/a/2930265/114029 Jun 2, 2012 at 3:48

6 Answers 6

25

There is a cleaner solution: Try adding GAE's memcache to your forced builtins.

In your PyDev->Interpreter-Python->ForcedBuiltins window, add the "google.appengine.api.memcache" entry and apply.

Double-click on the memcache errors to check them back, they disappear!

Please make sure that system pythonpath includes google APE install directory.

2
  • Not sure why but I had to remove the project from the eclipse and re-import it for this to work.
    – rzajac
    Nov 9, 2011 at 13:47
  • this worked for me in OS X Lion with Indigo and with the latest PyDev 2.5+ and GAE 1.6.6 after I removed and re-imported the GAE project as @Ralphz said...to add your Google App Engine folder in OS X, you will need to go into the .app folder... Jun 15, 2012 at 2:05
4

I'm a bit late to the party, but you can add the following comment in all of your files that use memcache to selectively switch off pydev analysis:

#@PydevCodeAnalysisIgnore

4

If you don't want to turn off all code analysis for your project/module, then just turn it off for that line. This answer explains that you can hit Ctrl+1 to bring up quick fix and insert #@UndefinedVariable at the end of the line.

3

What version of PyDev are you using? A recent one (1.5) or the old one referred by the Google tutorial?
See this thread.

There is a similar issue with PyROOT

Since PyDEV plugin does not read $HOME/.pystartup, touching functions/ classes is not a solution. Because it analyze the syntax and structures of python modules to be imported not on-the-fly but when I set the PYTHONPATH from Eclipse's preference panel.

So does your PYTHONPATH reference the Google library?


They might be an issue with code completion in 1.5 which could force you to disable code analysis: Pydev 1.5.0 code anlaysis breaks code pyqt4 code completion - ID: 2855598

have pyqt 4.5.4 installed.
Initially I had pydev 1.4.8 the open source version installed and code completion worked fine.
After updating to pydev 1.5.0, pyqt code completion stopped functioning.
After disabling the Pydev code analysis in "eclipse preferences -> pydev -> editor -> code analysis -> do code analysis?", code completion began working again for PyQt classes etc.

1
  • I'm using PyDev 1.5.0 but experienced the same with 1.4.8.
    – bocco
    Sep 24, 2009 at 6:40
3

This worked for me and it's different than the solutions above. Pretty straight forward: http://blog.kicaj.com/fixing-pydev-memcache-unresolved-import/

Just says to add the google_appengine folder to the pydev python interpreter library.

0

I fixed that by adding this few lines to my code on the top of my file:

from google.appengine.api import memcache
# work-around for Eclipse+PyDev+GAE memcache error
if not hasattr(memcache, 'set'):
    Client=None
    memcache.setup_client(Client)
    memcache = Client

You can commnet it out in production version.

It's only to keep eclipse happy and to let code completion work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.