如何修复AttributeError:';模块';对象没有属性';客户';在Google Cloud Interactive Shell中运行python时
我正在尝试运行一个python脚本,模拟交通传感器在我的Google Cloud Shell上实时向PubSub发送数据。我犯了这个错误如何修复AttributeError:';模块';对象没有属性';客户';在Google Cloud Interactive Shell中运行python时,python,python-2.7,google-cloud-platform,google-cloud-pubsub,google-cloud-shell,Python,Python 2.7,Google Cloud Platform,Google Cloud Pubsub,Google Cloud Shell,我正在尝试运行一个python脚本,模拟交通传感器在我的Google Cloud Shell上实时向PubSub发送数据。我犯了这个错误 Traceback (most recent call last): File "./send_sensor_data.py", line 87, in <module> psclient = pubsub.Client() AttributeError: 'module' object has no attribute 'Client
Traceback (most recent call last):
File "./send_sensor_data.py", line 87, in <module>
psclient = pubsub.Client()
AttributeError: 'module' object has no attribute 'Client'
没有
pubsub.Client
类。你
需要选择发布客户端
或订阅客户端
请参见pubsub.Client类在0.27.0版本的pubsub python包之前一直存在。所以我刚刚创建了一个虚拟环境,并在其中安装了pubsub的0.27.0版本。 以下是命令:
virtualenv venv
source venv/bin/activate
pip install google-cloud-pubsub==0.27.0
谷歌云平台的解决方案是:
virtualenv venv
source venv/bin/activate
pip install google-cloud-pubsub==0.27.0
#from google.cloud import pubsub
from google.cloud import pubsub_v1
#publisher = pubsub.PublisherClient()
publisher = pubsub_v1.PublisherClient()