csparpa / pyowm

A Python wrapper around the OpenWeatherMap web API
https://pyowm.readthedocs.io
MIT License
789 stars 171 forks source link

no attribute 'OWM' #292

Closed UNTITLED-CAT closed 5 years ago

UNTITLED-CAT commented 5 years ago

What's wrong? At start of the code the error jumps out. I am writing using Thonny. I work on raspberry pi 3 b +. thonny error: Traceback (most recent call last): File "/home/pi/pyowm.py", line 1, in <module> import pyowm File "/usr/lib/python3/dist-packages/thonny/backend.py", line 305, in _custom_import module = self._original_import(*args, **kw) File "/home/pi/pyowm.py", line 3, in <module> owm = pyowm.OWM('194277e0479d5a36ebb28e1a81c18006') AttributeError: module 'pyowm' has no attribute 'OWM'

terminal error: Traceback (most recent call last): File "pyowm.py", line 1, in <module> import pyowm File "/home/pi/pyowm.py", line 3, in <module> owm = pyowm.OWM('194277e0479d5a36ebb28e1a81c18006') AttributeError: 'module' object has no attribute 'OWM' code: `import pyowm

owm = pyowm.OWM('194277e0479d5a36ebb28e1a81c18006')

observation = owm.weather_at_place('London,GB') w = observation.get_weather() print(w)`

geofbaum commented 5 years ago

Just tested this on a linux comp, windows comp, and a raspberry pi 3 (not using thonny). The code runs fine. Not sure why it's not working but that top Thonny error makes it seem like it can't find the Pyowm package or it's not installed properly. Maybe @csparpa has a better clue but the issue is very likely not with Pyowm itself and definitely not with the code you used.

csparpa commented 5 years ago

It is indeed a problem with imports - on the client code, not PyOWM

@romaKadeta from your code, can you import PyOWM at all? Try:

from pyowm import OWM
UNTITLED-CAT commented 5 years ago

@csparpa The code was written in the editor Mu, but there is another error. Code:

`from pyowm import OWM

owm = pyowm.OWM('194277e0479d5a36ebb28e1a81c18006')

observation = owm.weather_at_place('London,GB') w = observation.get_weather() print(w) Error:Traceback (most recent call last): File "/home/pi/pyowm.py", line 1, in from pyowm import OWM File "/home/pi/pyowm.py", line 1, in from pyowm import OWM ImportError: cannot import name 'OWM' from 'pyowm' (/home/pi/pyowm.py) `

csparpa commented 5 years ago

@romaKadeta In the error msg you've posted, I can read:

ImportError: cannot import name 'OWM' from 'pyowm' (/home/pi/pyowm.py)

It looks like you're running a script named pyowm.py of your own, which attempts to import the installed PyOWM library. So, the name of the script and of the library clash.

Try to rename your script to any other thing different than "pyowm.py" and check if it works fine... Let me know!

tikky commented 4 years ago

I had similar issue. I am not sure what was causing the problem, but I've tried:

sudo apt-get update
sudo apt-get upgrade

and then I've uninstalled packages via:

sudo pip uninstall pyowm
sudo pip3 uninstall pyowm

and then installed back again for Python3 sudo pip3 install pyowm

After that the same script works fine for me without error message.