pycharm及其终端在Linux终端时看不到模块
我想从API下载一些有关城市中电车的实时数据。我有工作代码,但是只有在我复制它并打开Linux终端,输入Python3命令并将其粘贴到那里。在Pycharm中,我遇到了一个错误(推荐的选项安装程序包Google无法使用):
from google.transit import gtfs_realtime_pb2
ModuleNotFoundError: No module named 'google'
from google.transit import gtfs_realtime_pb2
import requests
feed = gtfs_realtime_pb2.FeedMessage()
response = requests.get('https://www.ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile/?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0Mi56dG0ucG96bmFuLnBsIiwiY29kZSI6MSwibG9naW4iOiJtaFRvcm8iLCJ0aW1lc3RhbXAiOjE1MTM5NDQ4MTJ9.ND6_VN06FZxRfgVylJghAoKp4zZv6_yZVBu_1-yahlo&file=feeds.pb')
feed.ParseFromString(response.content)
for entity in feed.entity:
if entity.HasField('trip_update'):
print(entity.trip_update)
I wanted to download some live data about Trams in my city from API. I have working code, but it works only if i copy it and open linux terminal, enter python3 command and paste it there. In PyCharm i got an error(recommended option install package google didn't work):
from google.transit import gtfs_realtime_pb2
ModuleNotFoundError: No module named 'google'
from google.transit import gtfs_realtime_pb2
import requests
feed = gtfs_realtime_pb2.FeedMessage()
response = requests.get('https://www.ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile/?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0Mi56dG0ucG96bmFuLnBsIiwiY29kZSI6MSwibG9naW4iOiJtaFRvcm8iLCJ0aW1lc3RhbXAiOjE1MTM5NDQ4MTJ9.ND6_VN06FZxRfgVylJghAoKp4zZv6_yZVBu_1-yahlo&file=feeds.pb')
feed.ParseFromString(response.content)
for entity in feed.entity:
if entity.HasField('trip_update'):
print(entity.trip_update)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您已经在Pycharm中安装了Google软件包,则可能是因为Pycharm内部使用的解释器与Linux终端本身中的一个不同。它可以解释为什么它在Pycharm本身中不起作用,而是在代码运行时在Linux终端内工作。
If you have the the google package already installed within PyCharm, it might be because the interpreter being used inside of PyCharm isn't the same one as the one in the Linux terminal itself. It would explain why it doesn't work within PyCharm itself but works within the Linux Terminal when the code is ran onto it.