Kapil Kaisare
Kapil Kaisare

Reputation: 61

Importing python classes in the Google App Engine

I am writing a GAE application and have run into an import problem.

My app.yaml has the following lines:

- url: /py/classes/  
  static_dir: py/classes

- url: /py/lib  
  static_dir: py/lib

- url: /py/bin/signin  
  script: py/bin/signin.py

I am keeping a python file, titled employee.py, containing the class employee, in the classes folder, and a signin.py script in the bin folder which tries - at the moment unsuccessfully - to import the employee class. I have tried, amongst others:

import employee  
import py.classes.employee  

Neither option works. Could you please let me know what I am doing wrong?

Thank you in advance.

Upvotes: 2

Views: 365

Answers (2)

Nick Johnson
Nick Johnson

Reputation: 101149

Any files specified as static files get uploaded separately from your code - they're not accessible by your Python code, so even with the PYTHONPATH set correctly, you won't be able to import them.

Upvotes: 1

lutz
lutz

Reputation:

The static_dir configuration option can not be used to extend PYTHONPATH. Using it you can serve static files like images, stylesheet, or Javascript files.

If you want to use normal Python modules just put them next to your main Python files.

Edit:

Are your directories Python packages that include the necessary __init__.py files?

Upvotes: 3

Related Questions