Search code examples
pythonlinuxapiimportweather-api

ImportError: cannot import name Weather even though i had installed the weather-api


I'm pretty new to this so please excuse my ignorance I'm trying my best to catch up and understand all the information out there.

Traceback (most recent call last):
  File "weather.py", line 1, in <module>
    from weather import Weather, Unit
  File "/home/kumyl/Documents/Projects/Weather-api-test/weather.py", line 1, in <module>
    from weather import Weather, Unit
ImportError: cannot import name Weather

This is the error I get when I do python weather.py or python3 weather.py. Not sure why that's happening. I looked online and found I needed to update pip, I have done that: pip --version gives me

pip 19.0.2 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

I think that's up to date? I don't really know the issue here. Some solutions said to make a virtual environment to run python? Not too sure what that is either so any help would be appreciated. Thank you.


Solution

  • python will try to import from your script first because it has the same name 'weather.py'. You should change the name of your file to a different one and it should work.