Reputation: 3
Hi everyone I'm struggling with AppEngine, I made my webapp on the development server, everything worked fine but once I deploy it gives me an ImportError. My main directory is as follows:
-/
-Several
-Folders
-...
*admin.py
*app.yaml
*db_objects.py
*index.yaml
*img_getter.py
*keys.py
*main.py
*main_handler.py
My app.yaml file:
application: myapplication (this is not the real name)
version: 1
runtime: python27
api_version: 1
threadsafe: yes
default_expiration: "7d"
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /css
static_dir: css
- url: /img
static_dir: img
- url: /images
static_dir: images
- url: /js
static_dir: js
- url: /admin.*
script: admin.app
login: admin
- url: /checkout.*
script: main.app
login: required
- url: /confirm.*
script: main.app
login: required
- url: /changeinfo.*
script: main.app
login: required
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
When I go to myaddress.appengine.com/admin it gives me this error:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~myapplication/1.383371027775991819/admin.py", line 7, in <module>
import img_getter
ImportError: No module named img_getter
This is the beginning of admin.py:
#coding=utf-8
import webapp2
from main_handler import Handler
import db_objects
from google.appengine.ext import db
import img_getter
from google.appengine.api import memcache
import keys
from datetime import date
class MainHandler(Handler):
def get(self):
self.redirect("/admin/noticias")
...
And this is the beginning of the img_getter.py file:
import gdata.photos.service
import gdata.media
import gdata.geo
def foo(variable):
...
def bar(variable):
...
#functions to get images from the google picassa service
The thing is I've been developing this webapp on the developer server and it's been working like a charm, I've even cleared the datastore and tried on several computers and it's still working, but when I try to test it on Google servers I'm finding this error.
I haven't define any reference on the app.yaml file as I think it's not necesary because it's not a library depending from google python API, am I wrong? Does anybody know what the problem is?
Thank you very much :)
Upvotes: 0
Views: 372
Reputation: 1697
You might need to import it as a package.
https://docs.python.org/2/tutorial/modules.html#packages
Create a folder called 'test' (or whatever you want) for img_getter.py and put it in there
Add a file called __init__.py
and save it in the folder you put img getting in. This file can be empty
call the import as import test.img_getter
Reference How to import python script files in folders on Google App Engine?
Cheers and good luck!
Upvotes: 1