我刚刚从文档页面复制并粘贴了这段代码,我使用pip成功地安装了这个包,但我总是遇到这个错误:
File "c:\Users\Guppy\Desktop\RACHEAL\RACHEALs Tools\Applications\Weather\weather.py", line 1, in <module>
from weather import Weather
ImportError: cannot import name 'Weather'代码如下:
from weather import Weather
weather = Weather()
# Lookup WOEID via http://weather.yahoo.com.
lookup = weather.lookup(560743)
condition = lookup.condition()
print(condition.text())
# Lookup via location name.
location = weather.lookup_by_location('dublin')
condition = location.condition()
print(condition.text())
# Get weather forecasts for the upcoming days.
forecasts = location.forecast()
for forecast in forecasts:
print(forecast.text())
print(forecast.date())
print(forecast.high())
print(forecast.low())有没有人知道哪里出了问题,或者有什么方法可以解决这个问题?
发布于 2018-01-17 12:24:31
使用python2.x,我相信仅仅通过pip安装天气API对Python3是不起作用的。
您可能需要重新安装它,才能使用pip3在Python3.x上运行
你可以试试:pip3 install weather-api
发布于 2018-03-19 05:40:34
看起来您的测试程序weather.py和您试图使用的模块之间存在名称冲突;Python尝试从您的程序而不是模块加载Weather类。尝试重命名测试仪,并删除关联的weather.pyc和/或__pycache__目录(如果存在)。
发布于 2018-01-17 12:45:04
当您的运行时查看本地解释器或virtual_env中的另一个时,Pip偶尔会将包安装到这两者中。
找出pip安装模块的位置,然后检查sys.path以查看是否列出了该目录。如果不是,那就是你的问题。Add是将其添加到路径或安装到它所在的位置。
https://stackoverflow.com/questions/48293507
复制相似问题