Get ImportError: No module named control when foll

2020-07-17 05:08发布

I am following this tutorial on setting up cloud endpoints in python on googles app engine and keep on getting an import error

ImportError: No module named control  

on the Generating the OpenAPI configuration file step when I input

python lib/endpoints/endpointscfg.py get_swagger_spec main.EchoApi --hostname echo-api.endpoints.projectid.cloud.goog

I followed these steps on a new account and still got this error. No idea what I am doing wrong/steps I am skipping.

here is the traceback:

Traceback (most recent call last):
  File "lib/endpoints/endpointscfg.py", line 625, in <module>
    main(sys.argv)
  File "lib/endpoints/endpointscfg.py", line 621, in main
    args.callback(args)
  File "lib/endpoints/endpointscfg.py", line 479, in _GenOpenApiSpecCallback
    application_path=args.application)
  File "lib/endpoints/endpointscfg.py", line 324, in _GenOpenApiSpec
    application_path=application_path)
  File "lib/endpoints/endpointscfg.py", line 181, in GenApiConfig
    module = __import__(module_name, fromlist=base_service_class_name)
  File "/home/hairyhenry/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/main.py", line 19, in <module>
    import endpoints
  File "/home/hairyhenry/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/__init__.py", line 29, in <module>
    from apiserving import *
  File "/home/hairyhenry/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/apiserving.py", line 74, in <module>
    from google.api.control import client as control_client
ImportError: No module named control

any insight would be fabulous

3条回答
够拽才男人
2楼-- · 2020-07-17 05:32

It is the same issue reported as #35901199 at the issue tracker, and it was marked as the intended behavior since the Control API is a part of the Google API Client Library and you can run the command 'pip install --upgrade google-api-python-client' to install it, which should solve the 'No module' errors. That said, we should also report this issue at the issue tracker here.

查看更多
霸刀☆藐视天下
3楼-- · 2020-07-17 05:38

This may be because of a library conflict between your environment and the app. This is what this page indicates, and the advice at the end worked for me:

I would recommend activating an empty virtualenv before running endpointscfg.py so that your system packages don't cause issues.

I did this with:

mkdir /tmp/ve
virtualenv /tmp/ve
/tmp/ve/bin/python lib/endpoints/endpointscfg.py ... 
查看更多
啃猪蹄的小仙女
4楼-- · 2020-07-17 05:45

I had the same issue using 2.0.0, but using the b2 release instead worked for me. Remove the lib folder and run:

pip install -t lib google-endpoints==2.0.0b2

Using this version will generate a file called echo-v1_swagger.json instead of echov1openapi.json as stated in the documentation, so you'll have to run the following to deploy the config file instead:

gcloud service-management deploy echo-v1_swagger.json

查看更多
登录 后发表回答