python telegram bot - bot run error - python

When I try to run a bot, I get this error message in the terminal:
zass#zass-system-product-name:~/python-telegram-bot/examples$python
echobot.py
/usr/local/lib/python2.7/dist-packages/python_telegram_bot-8.0-
py2.7.egg/telegram/utils/request.py:38: UserWarning: python-telegram-
bot wasn't properly installed. Please refer to README.rst on how to
properly install.
Traceback (most recent call last):
File "echobot.py", line 8, in <module>
import telegram
File "build/bdist.linux-x86_64/egg/telegram/__init__.py", line 94, in
<module>
File "build/bdist.linux-x86_64/egg/telegram/bot.py", line 34, in
<module>
File "build/bdist.linux-x86_64/egg/telegram/utils/request.py", line
33, in <module>
ImportError: No module named ptb_urllib3.urllib3
I'm running Python 2.7 on ubuntu, git and telegram bot are installed. - How can I fix it?

First of all make sure you have urllib3 installed. Sometimes urllib3 installation breaks. If for some reason your install of urllib3 is failing to include the util submodule, you could simply download the archive from the pypi page and copy the util folder from there to your urllib3 install location.
You may also issue the command below to get an up-to-date version:
sudo pip install urllib3 --upgrade
Then, see where your module is by starting a python interpreter and check where the urllib3 module is being loaded from:
python -c "import urllib3; print urllib3.__file__"
If all the above didn't work for you, make sure you're importing it right! and make sure there is no conflict.

If you clone the python-telegram-bot repo you need to run the following command before installing the code:
git submodule update --init --recursive
Then install the code with python setup.py install

Maybe you have 2 version of python and default version is 3.x
Try to check version of python
python -V
if default version is 3 then run your code with python version 2.
python2 echobot.py
it can be python2 or python2.7
Also it can be cause of versions of libs

Related

ModuleNotFoundError: No module named 'passlib' despite passlib already being installed

I have a python module that tries to import from passlib.hash import pbkdf2_sha256, however when running the module, I get the ModuleNotFoundError.
I have tried running the module in my base environment, a venv, in a poetry shell, and I've tried reinstalling passlib through poetry install, pip install, pip install --force-reinstall, and none of it gets the module to see passlib being installed. I'm at a complete loss as to why this library just won't work.
The full error message is:
poetry run src/api-keychain/main.py --help
Traceback (most recent call last):
File "XXX/src/api-keychain/main.py", line 5, in <module>
from crypto import encrypt_key, decrypt_key
File "XXX/src/api-keychain/crypto.py", line 5, in <module>
from passlib.hash import pbkdf2_sha256
ModuleNotFoundError: No module named 'passlib'
Since you mentioned about you successful installed passlib, I guess you might not install it with the python interpreter you are using.
First Try:
pip install passlib
If not work, it could because you have both Python2 and 3 try:
pip3 install passlib
python3 -m pip install passlib
And if you have an IDE like Pycharm, you can use it to check what packages are with the interpreter you are using via go to the Interpreter Settings.

Cannot install python six module

I have a server in the AWS cloud. It was running a flask API which calls the Google STT API fine. I then attempted to 'productionise' the API by setting up a virtualenv and getting the API to run there, with the intent of running Gunicorn.
When I tried to run the API in the virtual container it gave an error about importing the google api client. There was no google api client folder in my virtualenv so I copied folders across from the main python2.7 site-packages folder. Then I got an error saying it could not import six in googleapiclient/discovery.py. The error was "ImportError: No module named six".
There was no six directory in my virtualenv python folder. So I tried to copy across a folder named six-1.10.0.dist-info from my main python2.7 folder but that didnt help. I tried many things...such as forcing a reinstall but still the same error with the google api reference from googleapiclient/discovery.py. So I tried "sudo pip uninstall six; sudo pip install six". This successfully uninstalled, but now I cannot install again. When I run "sudo pip install six" I get the following:
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 48, in <module>
import six
ImportError: No module named six
I have also tried easy_install and options like --upgrade --ignore-installed but with no change in the behaviour.
What the heck is going on? Why cant I reinstall six? Why would it not be recognised anyway?
UPDATE
So this post stackoverflow.com/questions/13270877/… helped me to install six back into the main python environment. My API runs fine there now. But the same approach has not worked for the virtual environment.
Running "unset PYTHONPATH" seems to have helped me install modules into the virtualenv. The AWS image seems to have come with a python path already added that was confusing virtualenv. However I am still getting the nonsense below with six. What is going on?
(myprojectenv)[ec2-user#ip-172-31-29-83 myapi]$ python api.py
Traceback (most recent call last):
File "api.py", line 3, in <module>
from googleapiclient import discovery
File "/home/ec2-user/myapi/myprojectenv/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 20, in <module>
import six
ImportError: No module named six
(myprojectenv)[ec2-user#ip-172-31-29-83 myapi]$ pip install --upgrade six
Requirement already up-to-date: six in ./myprojectenv/lib/python2.7/site-packages

Python 3 installing tweepy

I have looked at all the forums, but nothing has worked so far. I have spent hours trying to install it so any help would be appreciated.
i have downloaded and unzipped tweepy, went on to the command prompt, typed "cd tweepy-master". This works, but when i type "python setup.py install" or "python setup.py build".
When i type "python setup.py install" the error says.
Traceback (most recent call last):
File "setup.py", line 4, in <module>
from setuptools import setup, find_packages
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\dist.py", line 103
except ValueError, e:
^
SyntaxError: invalid syntax
When i type "python setup.py build"
Traceback (most recent call last):
File "setup.py", line 4, in <module>
from setuptools import setup, find_packages
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "C:\Users\Sam Terrett\Documents\Portable Python 3.2.5.1\App\lib\site-packages\setuptools\dist.py", line 103
except ValueError, e:
^
SyntaxError: invalid syntax
I saw alot of people saying to use pip, but i am struggling to install that to.
Thanks for the help
pip is the good way to install a package. If you are not interested then you can install from source.
But you have to remember that, If you are using virtualenv or virtualenvwrapper then you can use python setup.py install otherwise you should use sudo python setup.py install.
If you are windows user then, open your cmd with administator privilege and type python setup.py install.
Have you installed Python using the Windows installer from python.org?
Cause this comes with pip already bundled into it. (I can not check the exact location atm, as I am on a Mac, but according to this SO post it should be located under C:\PythonX.X\Scripts, if you kept the default install location - otherwise it should be located in <path-to-python>\Scripts of course).
Otherwise pip can easily installed using this script. Simply call python get-pip.py in the script location and pip should be available afterwards (if not directly from commandline with pip, than at least by using python -m pip.)
Having pip finally available, you should be able to easily install tweepy calling pip install tweepy (or python -m pip install tweepy respectively).
For further information on pip and the other options to install it, check https://pip.pypa.io/en/stable/installing/.
PS. If installing the package via pip does not work, this may be a compatibility issue. According to the tweepy github-page python 3.2 is not amongst the supported python versions. So if your portable python really has an interpreter versioned 3.2.... (you can check the version of your interpreter running python from cmd, which should print something like > Python 3.X.X), the package may not run properly at all (even if you can install it without a problem).
As the portable python apparently is no longer supported anyways, it may be worth trying a different solution. There are plenty suggested on the portable python website (I just know about Anaconda, but this works flawlessly). But if you only want to use python with tweepy and don't need anything like scipy or numpy, I'd suggest simply downloading the installer from the official website. As said, pip gets shipped with the standard installation and can be used to easily install most of the packages you will need. (Except for e.g. the abovementioned scipy/numpy, which require additional non-python libraries whose "manual" installation may not be worth the trouble and hence legitimates the use of a more comprehensive environment like Anaconda).

Virtualenv package upgrade and install fails: cannot import name Message

I try to upgrade pip within a virtualenv following the instructions here. The upgrade fails because the system python cannot import the name Message from the email module.
(newsfeed)myhost:newsfeed admin$ pip install --upgrade pip
Traceback (most recent call last):
File "/Users/admin/newsfeed/newsfeed/bin/pip", line 7, in <module>
from pip import main
File "/Library/Python/2.7/site-packages/pip/__init__.py", line 9, in <module>
from pip.log import logger
File "/Library/Python/2.7/site-packages/pip/log.py", line 8, in <module>
from pip import backwardcompat
File "/Library/Python/2.7/site-packages/pip/backwardcompat/__init__.py", line 69, in <module>
from email import Message as emailmessage
ImportError: cannot import name Message
This problem is not just with upgrading pip but with installing anything within the virtualenv. When new package installations are attempted the same error occurs.
In a python terminal outside the virtualenv Message cannot be imported, but inside the virtualenv it can.
Also, in a different virtualenv on the same machine, there is no error installing or upgrading packages.
Why can't this virtualenv upgrade or install packages?
The standard library's email package is being shadowed (hidden) by a package or module named email(.py) in your path.
Locate the package by calling
python -c 'import email;print(email.__file__)'
and rename it or remove it.
Your pip is not inside the venv so you will probably not be able to upgrade it like this.
This is caused by the fact that you created a venv that uses system-packages. Remove the venv and recreate it by adding --no-site-packages as a parameter.

Installation Error while installing portia

Followed instructions on the github page. Of course, had to make minor changes since I was working with a windows 7 system. I got to the point post creating the virtual environment for portia to run. And I was trying to install the required packages using pip.
pip install -r requirements.txt
It failed with a log.
Now in the shell I try to run twistd, it gives error saying command not found. I even tried as follows:
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$ python ../../portia_env/Scripts/twistd.py -n slyd
Traceback (most recent call last):
File "../../portia_env/Scripts/twistd.py", line 13, in <module>
from twisted.scripts.twistd import run
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 53, in
<module>
_checkRequirements()
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 37, in
_checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zop
e.interface.
(portia_env)
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$
Is there an alternate procedure to follow in order to make this work on windows?
It looks like zope.interface didn't install when you ran:
pip install -r requirements.txt
Could you try running the following and see if it works?
pip install zope.interface

Categories

Resources