2

I am trying to import ZipCodeDatabase in helloworld.py.

  • helloworld.py exists at /google-app-engine/helloworld
  • ZipCodeDatabase module exists /usr/local/lib/python/python2.7/dist-packages
  • PYTHONPATH = /usr/local/lib/python/python2.7/dist-packages;/usr/local/lib/python/

When compiling helloworld I am still getting "ZipCodeDatabase module not found". Why isn't it being picked from the PYTHONPATH?

Josh Smeaton
  • 47,939
  • 24
  • 129
  • 164
Ray
  • 777
  • 2
  • 8
  • 22

1 Answers1

4

I highly doubt you've got a module called ZipCodeDatabase. That naming convention is typically reserved for a class that resides within a module. Modules are usually lowercase or lower_snake_case, to represent the file containing the module. I'm assuming you've installed pyzipcode here, but it may be a different module.

# assuming pyzipcode.py in the dist-packages directory
$ python -c 'from pyzipcode import ZipCodeDatabase'

If I'm wrong above, then are you sure you're running the version of python that has the ZipCodeDatabase module installed?

Some troubleshooting steps:

$ which python
$ python --version
$ python -c 'import ZipCodeDatabase'
$ ls -l /usr/local/lib/python2.7/dist-packages/ | grep -i zip

Also, is it really necessary for you to specify the PYTHONPATH line? Typically, the site-packages folder (and by extension I assume the dist-packages folder on Ubuntu) is included in the default PYTHONPATH, along with the current directory of the python module you're using.

How did you install the ZipCodeDatabase? Did you just drop the file in there? Try putting it alongside your helloworld.py file and try importing it then. Also, a full stack trace is useful information here, especially when others are trying to diagnose the problem you're having.

Edit:

Ok, now that I know you're using google app engine (should have been obvious from your use of paths - I'm sorry), it looks like it doesn't use the site-packages or dist-packages to load modules. You should create a sub-directory in your project with the relevant third party libraries, and add that sub-directory to your path. Disclaimer: I've never used GAE so I might be missing the mark with this.

Check out this answer for how to structure your project and add the extra directory to your path from within the application.

Community
  • 1
  • 1
Josh Smeaton
  • 47,939
  • 24
  • 129
  • 164
  • I can use ZipCodeDatabase when i use it in idle, but having the error no module found when used in the google app engine program. i am not sure whether this is a google app engine question or general python question. I looked how to import modules in google app engine and that seems also not working for me. – Ray Apr 20 '13 at 16:35
  • @user189364 take a look at this answer and question then: http://stackoverflow.com/questions/2710861/how-to-import-modules-in-google-app-engine – Josh Smeaton Apr 21 '13 at 03:45