pyowm.exceptions ModuleNotFound
JerryTheQuad opened this issue · comments
Hi,
Here is my code. It's a Telegram bot I created to show weather. In Google Collab it works OK, but in PythonAnywhere or Repl.it it shows this:
from pyowm.exceptions import *
ModuleNotFoundError: No module named 'pyowm.exceptions'
The actual code:
from pyowm import OWM
from pyowm.exceptions import *
import telebot
owm = OWM('xxxxxxxxxxxxxxxxxxxxxxxxxxxxx', language='ru')
bot = telebot.TeleBot("My Telegram ID Here. Deleted it")
@bot.message_handler(commands=['start', 'help'])
def commands(message):
if message.text == '/start':
bot.send_message(message.from_user.id, """Привет! Я могу найти тебе погоду в нужном городе. Условие:
1. Никому не рассказывай о бойцовском клубе
2. Пиши в подобном формате 'Москва, РФ' или 'Москва'
3. Только на русском языке
У меня есть чувство, что мы с тобой сработаемся.
""")
elif message.text == '/help':
bot.send_message(message.from_user.id, """Смотри. Ты поможешь мне, я помогу тебе:
1. Я понимаю только в формате, подобном этому — 'Москва, РФ' или 'Москва'
2. Если я не отвечаю, то здесь две причины: или меня отключили, или ты вводишь город/страну не в том формате.
Но я тебе пишу, верно? Значит с меня взятки гладки.
""")
@bot.message_handler(content_types=['text'])
def handle_messages(message):
try:
obs = owm.weather_at_place(message.text)
w = obs.get_weather()
now_temp = w.get_temperature(unit='celsius')
status = w.get_detailed_status()
bot.send_message(message.from_user.id, f'''
==========
Min t: {now_temp.get("temp_min")}°
Avg t: {now_temp.get("temp")}°
Max t: {now_temp.get("temp_max")}°
==========
{status.title()}
''')
except api_response_error.NotFoundError:
bot.send_message(message.from_user.id, 'Врёшь, нет такого города')
bot.polling()
@JerryTheQuad
I think this is due to the fact that you don't have PyOWM installed on those environments! Can you check if PyOWM is among the installed third party libraries (remember that - of coures - it is not part of the Python standard library!)
Also please notice I've patched your code snippet so that your API key is now masked... NEVER expose your API secrets! This is a public repository! ;-)
Let me know
@JerryTheQuad consider changing pyowm.exceptions
to pyowm.commons.exceptions
@JerryTheQuad
I think this is due to the fact that you don't have PyOWM installed on those environments! Can you check if PyOWM is among the installed third party libraries (remember that - of coures - it is not part of the Python standard library!)Also please notice I've patched your code snippet so that your API key is now masked... NEVER expose your API secrets! This is a public repository! ;-)
Let me know
Wow, thank you for responding!) I checked on Repl.it and pyOWM is installed as a third-party package. Here is a screenshot. As an aside note, the code works fine on Google Collab. Have a great day!)
Hi @JerryTheQuad sorry I've missed it: FabianReister posted the solution, please check his comment
It's an import error: you're importing from the wrong path, as the exceptions module is not in the root path of the project.
Hi @JerryTheQuad sorry I've missed it: FabianReister posted the solution, please check his comment
It's an import error: you're importing from the wrong path, as the exceptions module is not in the root path of the project.
Thank you!) Just did that, this is what I get now:
Traceback (most recent call last): File "main.py", line 6, in <module> owm = OWM('xxxxxxxxxxxxxxxxxxxxxxxxxxx', language='en') TypeError: __init__() got an unexpected keyword argument 'language'
That's because you're intializing the library the wrong way.
Take a look at pyowm documentation about it:
https://pyowm.readthedocs.io/en/latest/v3/code-recipes.html#language-setting
That should fix the language issue
That's because you're intializing the library the wrong way.
Take a look at pyowm documentation about it:
https://pyowm.readthedocs.io/en/latest/v3/code-recipes.html#language-setting
That should fix the language issue
That's because you're intializing the library the wrong way.
Take a look at pyowm documentation about it:
https://pyowm.readthedocs.io/en/latest/v3/code-recipes.html#language-setting
That should fix the language issue
Thank you, it really solved the language problem)