Although I install python-telegram-bot, error of no module named 'telegram'
Asked Answered
I

10

5

I installed telegram packages. But when I try to run the simple example, echobot.py, I got an error:

Traceback (most recent call last):
    File "echobot.py", line 8, in <module>
import telegram ImportError: No module named 'telegram'

Can anyone help me?

I install using git:

$ git clone https://github.com/python-telegram-bot/python-telegram-bot

after this:

$ python -i
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import telegram

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: No module named 'telegram'
Iodic answered 28/7, 2017 at 21:30 Comment(0)
C
12

You are not installing it. You are just downloading it.
Run these:

cd python-telegram-bot
python setup.py install

(stated in readme of the GitHub page)

Alternatively, you can use pip. It's easier to use.

pip install python-telegram-bot
Concenter answered 28/7, 2017 at 21:34 Comment(4)
Thanks @Mehmet for the answer, but I try this: C:\Python27>pip install python-telegram-bot Requirement already satisfied: python-telegram-bot in c:\users\mahyar\appdata\local\programs\python\python35-32\lib\site-packages\python_telegram_bot-7.0.1-py3.5.egg Requirement already satisfied: future>=0.16.0 in c:Iodic
Maybe the problem is because of multiple versions of python! Any recommendation?Iodic
Can you try running commands with full path? e.g: C:\Python27\scripts\pip.exe install python-telegram-bot - pip is under scripts folderConcenter
I uninstalled other pythons, then use this: $ git clone github.com/python-telegram-bot/python-telegram-bot --recursive it means I added --recursive. Hopefully, it worked! Thanks @Mehmet for help, it was really helpful.Iodic
R
1

I noticed when I import telegram.ext, it does not find .ext. The issue was caused by telegram and python-telegram modules being installed. Delete these and install only python-telegram-bot. It should work.

Recrimination answered 19/2, 2022 at 16:21 Comment(0)
B
1

Try to uninstall it by pip uninstall python-telegram-bot

And after that install it again pip install python-telegram-bot

Beasley answered 25/1, 2023 at 17:57 Comment(0)
C
0

For my case, I solved it this way.enter image description here

pip install telegram
Cavefish answered 2/2, 2021 at 19:4 Comment(1)
This just installs an empty package from pypi.org/project/telegramHyp
P
0

If you have named your python file as telegram.py then it will throw this error because the program is calling ext function from the file itself. Try renaming your python file to something else it will work.

Py answered 29/10, 2022 at 14:45 Comment(0)
G
0

In my case, I had two python versions installed. A quick solution is to idetify which python your code is using. Then go to bin directory where the python is installed. Find the pip binary name inside that using command

ls -lrt | grep pip

In my cases the name was pip3.6. So use then use that pip name and execute from same directory

pip3.6 install python-telegram-bot

Long term fix is to add your pip3.6 shortcut in /usr/bin or /usr/loca/bin and install packages using pip3.6 command

Guadalupe answered 15/12, 2022 at 3:50 Comment(0)
P
0

You have also to pay attention to the python version which is launching the code. May be that your dependances have been installed in another python version

Platas answered 11/7 at 11:16 Comment(0)
G
-1

Thre problem is in line with smth like

sys.path.append(os.path.join(os.path.abspath('.'), 'lib'))

in bot_gae.py.

You have to point at REAL place, where you've installed python-telegram-bot.

In my case it's ./lib in project directory.

Gish answered 18/10, 2017 at 9:48 Comment(0)
S
-2

It seems like the python-telegram-bot package is not properly installed in your Python environment. Here's how you can install it using pip, which is the standard package manager for Python:

  1. First, make sure you have pip installed. You can check this by running:
pip --version

If you get a version number, then pip is installed. If not, you'll need to install it.

  1. Install python-telegram-bot using pip. Run the following command in your terminal or command prompt:
pip install python-telegram-bot

This command will download and install the python-telegram-bot package along with its dependencies.

Once the installation is complete, you should be able to run your echobot.py script without any issues. If you still encounter problems, ensure that you are using the correct Python environment (the one where pip installed the package). You can also try restarting your Python environment or your terminal after the installation.

Spoofery answered 17/3 at 11:11 Comment(0)
S
-3

Install

pip install django-telegrambot

Configure your installation

settings.py

INSTALLED_APPS = ( ... 'django_telegrambot', )

Siegbahn answered 14/6, 2020 at 6:18 Comment(1)
I dont think this is the library, that questioner wanted to installDoublestop

© 2022 - 2024 — McMap. All rights reserved.