How to fix ImportError: No module named 'telebot' - python

I'm configuring a bot to send alerts from Zabbix, so I installed Python and the modules:
sudo apt install python python-pip python-setuptools
After that, I installed the bot API to use on Zabbix:
python -m pip install --user pyTelegramBotAPI
Created the script in /usr/lib/zabbix/alertscripts/ :
#!/usr/bin/env python
import telebot,sys
BOT_TOKEN='123TOKENAQUI321'
DESTINATION=sys.argv[1]
SUBJECT=sys.argv[2]
MESSAGE=sys.argv[3]
MESSAGE = MESSAGE.replace('/n','\n')
tb = telebot.TeleBot(BOT_TOKEN)
tb.send_message(DESTINATION,SUBJECT + '\n' + MESSAGE)
Changed permissions:
sudo chmod +x telegram
sudo chown -R zabbix telegram
And when testing the script on terminal or Zabbix the following error appears:
Traceback (most recent call last): File
"/usr/lib/zabbix/alertscripts/telegram", line 2, in
import telebot,sys ImportError: No module named 'telebot'
I tried to solve by installing the module:
python -m pip install --user telebot
Installing the module did not solve it, so I tried to use python3, and the script on the terminal worked, but in Zabbix still showing the same error. I ended up going back to python.
The telebot module does not appear with pip list, only inside the python terminal using the command help ("modules").
Does anyone know that may be causing the problem?

I managed to solve it using python3, but this time I removed the other versions of python completely before installing again, the steps were as follows:
sudo python -m pip uninstall pyTelegramBotAPI
sudo apt remove python python-pip python-setuptools
sudo apt install python3 python3-pip python3-setuptools python3-six
sudo python3 -m pip install pyTelegramBotAPI six
sudo pip install six

For like these errors, reinstall the library or use (--upgrade) when you install it!
like this:
pip uninstall telebot
pip install pyTelegramBotAPI
pip install pytelegrambotapi --upgrade

Related

Can't import package in python3.6

I have installed python3.5 on my server. I installed pysher with pip3, everything works fine, in python3.5 terminal, I can use import pysher without error. Now, I develop script, where is some python3.6 features, so I installed python3.6 on my server and now, I am not able to import pysher in python3.6 terminal:
>>> import pysher
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pysher'
So I tried install pysher again:
# pip3 install pysher
The program 'pip3' is currently not installed. You can install it by typing:
apt install python3-pip
Even when I konw I have installed python3-pip, I tried it agian:
# apt install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pip is already the newest version (8.1.1-2ubuntu0.4).
0 upgraded, 0 newly installed, 0 to remove and 138 not upgraded.
Of course, I can rewrite my second script to work with python3.5, but I am curious why it is not working and how to repair it.
UPDATE 1:
dpkg -L python3-pip | grep bin
/usr/bin
/usr/bin/pip3
export PATH="$PATH:/usr/bin/pip3"
pip3 search pysher
The program 'pip3' is currently not installed. You can install it by typing:
apt install python3-pip
This did not work, so I try get version of pip3:
# /usr/bin/pip3 --version
-bash: /usr/bin/pip3: No such file or directory
pip3 is not in /usr/bin/.
Run dpkg -L python3-pip to find out where apt installed your pip3. Then
export PATH="$PATH:/usr/bin/mypippath
Will add it to your path. After that, trypip3 again.
There is two way to work with pip files.
1 - Inside of a program file like this :
import pip
pip.main(["install" , "package"])
2 - Getting into the scripts folder in Python directory and command line and printing the following content :
C:\Python\Python35\Scripts\pip.exe install package

Pipenv-Error: ModuleNotFoundError: No module named 'pip._internal' [duplicate]

This question already has answers here:
pip: no module named _internal
(30 answers)
Closed last month.
Today, I installed Pipenv via
pip install pipenv
As mentioned in the documentation I went to a test directory and created a new virtual environment using
pipenv shell
and tried to install a package via
pipenv install numpy
I got the following error message:
Installing numpy…
⠧
Error: An error occurred while installing numpy!
Traceback (most recent call last):
File "/Users/florian/.local/share/virtualenvs/test-bJfQ6Jzk/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
This error occurs even after reinstalling pipenv, deleting all files and recreate the environment. It also had no impact if I ran pipenv install numpy inside or outside the environment.
Python 3.6.3
Pipenv 11.10.1
Thank you in advance.
I have had the same issue (python 3.5/Ubuntu 16.04LTS). Reinstalling pip with:
sudo apt install python-pip python-pip3 --reinstall
didn't solve the issue with me.
What worked in my case was reinstalling pipenv itself, from pip:
sudo pip3 install pipenv --force-reinstall
If you are running python 2.x or if your system is different than mine, you can try to replace pip3 with pip in the command:
sudo pip install pipenv --force-reinstall
Ubuntu 18.04, Python 3.6 :
Reinstalling pipenv did not work for me. Reinstall pip3 was the only issue, but
sudo apt install python3-pip
did not work too. Found a link to get pip3 in AskUbuntu.com which worked fine :
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py --force-reinstall
After trying around for a while, I fully reinstalled pip. This solved the problem and everything is working now as expected.
Before providing the two commands, which solved the problem, I want to specify some things:
I'm on MacOS
python stands for python3 (added an alias for that, because I only use python3)
pip is on version 9 and NOT 10
Here are both commands:
sudo pip uninstall pip
sudo python get-pip.py
I resolved problem using this command:
pip3 install pipenv --upgrade
The environment pipenv is trying to use may be corrupt for the current project.
Removing it, and re-running pipenv install worked in my case. I am on Fedora 35, where the python virtualenvs are located in ~/.local/share/virtualenvs/, this may be different in your case.
find out which virtualenvs are on your disk:
ls ~/.local/share/virtualenvs/
remove the ones belonging to your project:
rm -rf ~/.local/share/virtualenvs/yourprojectname*

How can I install BeautifulSoup? I keep getting "No module named bs4"

When I try to
import bs4
I keep getting the error
ImportError: No module named bs4
I have tried to address this by trying all of the following (individually and together) with Python 2 and Python 3 and have had no success. What's going wrong?
sudo pip2 install beautifulsoup4
sudo pip3 install beautifulsoup4
sudo apt-get install python-bs4
sudo apt-get install python3-bs4
Downoad it from Pypi beatifulsoup4
and find setup.py file after extracting, then install it with
sudo python setup.py install

ImportError: No module named extern

I'm getting this error when trying to install any package with pip. I have two pip instances, one with Python 2.7 and other with Python 3.
Could not import setuptools which is required to install from a source distribution.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 375, in setup_py
import setuptools # noqa
File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extern.six.moves import filterfalse, map
File "/usr/local/lib/python2.7/dist-packages/setuptools/extern/__init__.py", line 1, in <module>
from pkg_resources.extern import VendorImporter
ImportError: No module named extern
Even when I try to install the 'extern' module I get this error. Also when installing with Python itself, like python setup.py install.
Thanks in advance.
sudo apt-get purge python-pkg-resources
sudo apt-get -f install
here actually packages are removed and
purged (any configuration files are deleted too).
-f : Attempt to correct a system with broken dependencies in place.
sudo pip install packagename
#sourcehere
Do this it will work
sudo pip install -U setuptools
I know this is an old thread, but I just wanted to contribute since I ran into this issue and this thread kept coming up in the results.
Note: This was on MacOS 10.12. My shell is zsh and I already have brew installed
First I ran each of these commands
brew install python
brew install python3
This will either install it or you'll receive an "already installed" message as I did.
Next, run the following command
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
And last:
sudo python get-pip.py
Final note: for my install to work, I ended up having to run the command with pip3
sudo pip3 install nameofinstallhere
Not sure whether it is installation issue or packege but it seems like you will not be able to import any package of them, if you have installed python perfectly then
try this commands
step 1 :
$which pip
/usr/local/bin/pip
step 2 :
/usr/local/bin/pip install django
or any of your package name.
I am considering ubuntu(OS)
You can try the following command; it has worked for me:
sudo apt-get install --reinstall python-setuptools

ImportError No module named pyaudio

I am writing a program in Python on RaspberryPi, But I am getting an error
ImportError No module named pyaudio
After that I tried
git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
but again get another
fatal: destination path 'pyaudio' already exists and is not an empty directory.
Can you please guide me that how do I install PyAudio in RaspberryPi
Remove the directory PyAudio which already presen in /home/pi and then try these steps
sudo apt-get install git
sudo git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo apt-get install python-dev
cd pyaudio
sudo python setup.py install
or also you can try this
sudo apt-get install python-pyaudio
let us know if u need more assistance or any other trouble
If
sudo apt-get install python-pyaudio
did’t work try:
sudo apt-get install python3-pyaudio
You can simply install PyAudio by executing this command:
pip install pipwin
pipwin install pyaudio
python -m pip install pyaudio
This command works if you already have pip installed.
If not, first install pip and ty
download suitable version of PyAudio File: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio
Then Open CMD
type : C:\Users\Programs\Python\Python37\Scripts add "pip install"
file location where you download the PyAudio whl file add File name
example:C:\Users\Programs\Python\Python37\Scripts>pip install C:\Users\Desktop\Projects\PyAudio-0.2.11-cp37-cp37m-win_amd64.whl
Install using below command
conda install -c anaconda pyaudio
This command worked for me:
conda install -c anaconda pyaudio
pip install pyaudio
this worked for me,hope it helps you too.

Categories

Resources