Python Telegram Bot Package: Runtime Error on Windows Machine

Hi everyone,

I’m having trouble with my telegram bot project. It works fine on my Mac, but I’m getting an error when I try to run it on Windows. Here’s what’s happening:

(botenv) C:\Projects\TelegramBot> python bot_script.py
Traceback (most recent call last):
  File "C:\Projects\TelegramBot\bot_script.py", line 1, in <module>
    from telegram.ext.updater import Updater
ModuleNotFoundError: No module named 'telegram.ext.updater'

I’m using Windows 11 Pro and Python 3.9.15. I’ve already tried:

  • Uninstalling and reinstalling the package
  • Setting up a new virtual environment
  • Restarting my computer

None of these fixed the issue. I’ve double-checked my installed packages, and the telegram bot package is there.

Has anyone run into this problem before? Any ideas on how to fix it? I’m pretty stumped at this point. Thanks for any help you can give!

yo, i had similar probs on my windows laptop. try using ‘from telegram import bot’ instead. also, make sure ur using the right version of the package that works with ur python. if nothin else works, maybe try runnin it in WSL? that sometimes fixes weird windows issues for me

I’ve encountered a similar issue when working with Python packages on Windows. In my experience, the problem often lies in how Windows handles Python package imports compared to Unix-based systems.

One solution that worked for me was to modify the import statement. Instead of using ‘from telegram.ext.updater import Updater’, try changing it to ‘from telegram.ext import Updater’. This slight modification in the import structure sometimes resolves the ModuleNotFoundError on Windows machines.

If that doesn’t work, another approach I’ve found helpful is to explicitly specify the package version when installing. For instance, you could try ‘pip install python-telegram-bot==13.7’ (or whichever version you’re using), ensuring you’re using a version compatible with your Python installation.

Lastly, double-check your PYTHONPATH environment variable. Sometimes, Windows doesn’t set this correctly, which can lead to import issues. You might need to manually add your project directory to the PYTHONPATH.

Hope one of these solutions helps you resolve the issue!