天气问题-从天气导入天气,单位ImportError:无法从“天气”导入名称“天气”

时间:2020-01-17 08:08:37

标签: python weather weather-api

我收到此错误:

从天气导入天气,单位ImportError:无法导入名称 “天气”从“天气” (C:Users \ Python \ Python37 \ site-packages \ weather__init __。py)

我已使用pip安装了Weather,但仍然出现错误。我正在尝试安装weather-api,但没有找到weather-api的匹配发行版。

from weather import Weather, Unit
import time

class WeatherData:
temperature = 0
weather_conditions = ''
wind_speed = 0
city = ''

def __init__(self, city):
    self.city = city
    weather = Weather(unit = Unit.CELSIUS)
    lookup = weather.lookup_by_location(self.city)
    self.temperature = lookup.condition.temp
    self.weather_conditions = lookup.condition.text
    self.wind_speed = lookup.wind.speed

def getTemperature(self):
    return self.temperature + " C"

def getWeatherConditions(self):
    return self.weather_conditions

def getWindSpeed(self):
    return self.wind_speed + " kph"

def getCity(self):
    return self.city

def getTime(self):
    return time.ctime()
if __name__ == "__main__":
current_weather = WeatherData('London')
print(current_weather.getTemperature())
print(current_weather.getWeatherConditions())
print(current_weather.getTime())

0 个答案:

没有答案