Reputation: 2261
When I try to integrate google cloud endpoints into an existing project I get this error:
ImportError: No module named endpoints
I've already added endpoints to my app.yaml file. The endpoints api file that works externally with its own app.yaml file, but gives the error when run from within the project directory. I'm routing all api calls to "endpoints_api.py" for simplicity. Maybe I'm missing something.
This is my directory setup:
-project
-handlers
-media
-templates
-webapp2_extras
__init__.py
app.yaml
main.py
endpoints_api.py
Here is my app.yaml file:
application: project-aplha
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
# Endpoints Api
- url: /_ah/spi/.*
script: endpoints_api.APPLICATION
- url: /favicon\.ico
static_files: media/favicon.ico
upload: media/favicon.ico
- url: /media
static_dir: media
# Main Script
- url: /.*
script: main.APPLICATION
libraries:
- name: endpoints
version: 1.0
- name: webapp2
version: latest
- name: jinja2
version: latest
- name: pycrypto
version: latest
And a sample of a handler class (if that matters):
class SignupHandler(base.BaseHandler):
def get(self):
return self.render_template('sighup.html')
def post(self):
name = self.request.get('name')
email = self.request.get('email')
password = self.request.get('password')
Perhaps the endpoints_api.py file too:
import endpoints
from google.appengine.ext import ndb
from protorpc import messages
from protorpc import message_types
from protorpc import remote
class Task(messages.Message):
name = messages.StringField(1, required=True)
owner = messages.StringField(2)
class TaskModel(ndb.Model):
name = ndb.StringProperty(required=True)
owner = ndb.StringProperty()
@endpoints.api(name='tasks', version='v1',
description='API for Task Management')
class TaskApi(remote.Service):
@endpoints.method(Task, Task,
name='task.insert',
path='task',
http_method='POST')
def insert_task(self, request):
TaskModel(name=request.name, owner=request.owner).put()
return request
APPLICATION = endpoints.api_server([TaskApi])
Upvotes: 1
Views: 1075
Reputation: 14354
I'm getting the same error with the latest AppEngine SDK 1.9.40 on OS X. The endpoints
module is not in the Python module search path and thus when your code runs import endpoints
, it fails with an ImportError.
Even running with the GUI GoogleAppEngineLauncher, the module is unreferenced.
On OS X, the module is at /usr/local/google_appengine/lib/endpoints-1.0/endpoints
. You can verify this by adding it to your PYTHONPATH and then from the interpreter run import endpoints
. This should work although it will fail as it has an internal reference to `protorpc'.
Unfortunately on the command-line, the dev_appserver.py
fails to reference PYTHONPATH and thus you continue to get an ImportError with a command like:
dev_appserver.py --datastore_path=datastore.db .
And for the record, I am including it in my app.yaml
:
libraries:
- name: ssl
version: latest
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
- name: pycrypto
version: "2.6"
- name: endpoints
version: "1.0"
Upvotes: 1
Reputation: 4619
You must run your project with latest version of Google Cloud SDK.
Switch to your project folder and run it by the following command:
dev_appserver.py .
Upvotes: 0