Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access Google AppEngine external libraries

Please help... I am running some python code from cygwin and I can't import the GoogleAppEngine (GAE) External Data API. I think this may be an environment variable problem. I am able to run GAE and the 'remote_data_api_shell.py' from the command line, but I cannot run a python module that references GAE.

I'm in trial-and-error mode trying every combination of environment variable strings I can think of. Nothing works and my frustration is mounting.

  1. GAE(1.5) is located in (windows path): C:\Program Files (x86)\Google\google_appengine

  2. Here is my Python Error:

Traceback (most recent call last): File "/cygdrive/c/data/my-program/MyProgram.py", line 48, in '<'module'>'

from Model import MyStoredObject File "/cygdrive/c/data/my-program/Model.py", line 6, in '<'module'>' from google.appengine.ext import db ImportError: No module named google.appengine.ext

  1. I setup my environment variables in my cygwin bashrc file. My bashrc file contains

    GAE_HOME="/cygdrive/c/Program\ Files\ (x86)/Google/google_appengine"

    I tried many combinations of strings and characters here.

    PATH="$PATH:$GAE_HOME

    PYTHONPATH="$PYTHONPATH:$GAE_HOME:$GAE_HOME/lib/yaml/lib:

    Also tried $GAE_HOME/google/appengine/ext and many more...

    export PYTHONPATH

    export PATH

    export GAE_HOME

How can I make this work? Anything obvious to a GAE expert that I'm doing wrong here?

like image 836
codingJoe Avatar asked May 13 '11 05:05

codingJoe


2 Answers

I have this at the top of scripts I run that need to interact with the appengine SDK

import sys
import os

# locate app-engine SDK
AE_PATH = "/path/to/sdk/google_appengine/"

# path to app code
APP_PATH = os.path.abspath(".")

# load the AE paths (as stolen from dev_appserver.py)
EXTRA_PATHS = [
    APP_PATH,
    AE_PATH,
    os.path.join(AE_PATH, 'lib', 'antlr3'),
    os.path.join(AE_PATH, 'lib', 'django'),
    os.path.join(AE_PATH, 'lib', 'ipaddr'),
    os.path.join(AE_PATH, 'lib', 'webob'),
    os.path.join(AE_PATH, 'lib', 'yaml', 'lib'),
    os.path.join(AE_PATH, 'lib', 'fancy_urllib'), # issue[1]
]
sys.path = EXTRA_PATHS + sys.path

[1] fancy_urllib issue

Hopefully that points you in the right direction

like image 94
Chris Farmiloe Avatar answered Nov 14 '22 11:11

Chris Farmiloe


This should fix the paths:

sdk_path = "/path/to/sdk/google_appengine/"
sys.path.insert(0, sdk_path)
import dev_appserver
dev_appserver.fix_sys_path()
like image 21
enceladus Avatar answered Nov 14 '22 11:11

enceladus