ImportError:没有名为端点的模块

时间:2019-03-31 21:55:47

标签: python google-app-engine google-cloud-endpoints

在从github下载的示例目录中进行设置时可以正常工作,但是现在我已经构建了自己的API,开发服务器启动了,但是用CURL击中它时会抛出此错误:

  

$ dev_appserver.py ./app.yaml

INFO     2019-03-31 21:48:38,215 api_server.py:275] Starting API server at: http://localhost:54462
INFO     2019-03-31 21:48:38,225 api_server.py:265] Starting gRPC API server at: http://localhost:54464
WARNING  2019-03-31 21:48:38,227 dispatcher.py:338] Your python27 micro version is below 2.7.12, our current production version.
INFO     2019-03-31 21:48:38,386 dispatcher.py:256] Starting module "default" running at: http://localhost:8080
INFO     2019-03-31 21:48:38,395 admin_server.py:150] Starting admin server at: http://localhost:8000
INFO     2019-03-31 21:48:48,055 instance.py:294] Instance PID: 96100
INFO     2019-03-31 21:48:48,076 module.py:861] default: "GET /_ah/start HTTP/1.1" 404 -
ERROR    2019-03-31 21:48:48,113 wsgi.py:263] 
Traceback (most recent call last):
  File "/Users/me/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Users/me/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Users/me/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/Users/me/Documents/GitHub/activitylogs_api/main.py", line 19, in <module>
    import endpoints
ImportError: No module named endpoints
INFO     2019-03-31 21:48:48,120 module.py:861] default: "GET /_ah/api/activitylogs/v1/list HTTP/1.1" 500 -

但是python -m pip列表显示了这些:

  

google-endpoints 4.8.0
  google-endpoints-api-management 1.11.0

开发服务器是否在其他环境下运行?它在其他示例文件夹中时正在工作,但不在此处。还有一个./lib文件夹,其中包含通过此命令安装的要求:

  

pip install --target lib --requirement requirements.txt   --ignore-installed

其中当然包括端点...

$ gcloud version
Google Cloud SDK 237.0.0
app-engine-python 1.9.83
app-engine-python-extras 1.9.74
beta 2019.02.22
bq 2.0.42
cloud-datastore-emulator 2.1.0
core 2019.03.01
gsutil 4.37
kubectl 2019.03.01

这是main.py的(开头):

# [START imports]
import endpoints
from endpoints import message_types
from endpoints import messages
from endpoints import remote
from datetime import datetime
# [END imports]

有趣的是,如果我输入python并尝试导入,则会收到其他错误:

$ python
Python 2.7.10 (default, Feb 22 2019, 21:17:52) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import endpoints
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/me/Library/Python/2.7/lib/python/site-packages/endpoints/__init__.py", line 25, in <module>
    from protorpc import message_types
ImportError: No module named protorpc
>>> 

而python3则显示dev appserver所显示的相同错误。但是我看不到如何以python3的形式启动appengine服务器,因为app.yaml具有以下功能:

  

运行时:python27

1 个答案:

答案 0 :(得分:0)

缺少以下内容的appengine_config.py:

from google.appengine.ext import vendor

# Add any libraries installed in the `lib` folder.
vendor.add('lib')