Google Cloud SDK importError: no module named cloud.google

匆匆过客 提交于 2019-12-11 07:31:06

问题


I am new to Linux and trying to run a Python script that needs the following: 'from google.cloud import pubsub'

I'm getting the following error:

Traceback (most recent call last):
  File "file.py", line 2, in <module>
    from google.cloud import pubsub
ImportError: No module named google.cloud

How can I give access to this module? I have installed Google's Cloud SDK. I assume it has something to do with providing the path to this SDK "module" in some file?


回答1:


If this only happened when you deployed to app engine, then considering the following solution (it worked for me):

1, in the same directory of your app engine project (usually where you put your **.py, **.yaml, and index.html), add a python file named "appengine_config.py"

2, put the following code into your appengine_config.py:

# appengine_config.py
from google.appengine.ext import vendor

# Add any libraries install in the "lib" folder.
vendor.add('lib')

3, make sure on that directory you also has a "lib" folder that contains your library import (check if google.cloud is there)

4, deploy it and that problem should be resolved.




回答2:


If you want use pubsub in Python script, you should install via pip like this:

  • Install pip and virtualenv

    sudo apt-get install python-pip python-dev build-essential
    sudo pip install virtualenv
    
  • Create new environment and activate that

    cd project-folder
    virtualenv env
    source env/bin/activate
    
  • Install pubsub module

    pip install google-cloud-pubsub
    


来源:https://stackoverflow.com/questions/43462495/google-cloud-sdk-importerror-no-module-named-cloud-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!