Getting python ImportError: cannot import name 'appengine' - python

I have single line in my py file:
from requests_toolbelt.multipart.encoder import MultipartEncoder
When I run it, I am getting following error:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/requests_toolbelt/_compat.py", line 49, in <module>
from requests.packages.urllib3.contrib import appengine as gaecontrib
ImportError: cannot import name 'appengine'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\workspaces\workspace6\Expe\Exp.py", line 8, in <module>
from requests_toolbelt.multipart.encoder import MultipartEncoder
File "/usr/lib/python3.6/site-packages/requests_toolbelt/__init__.py", line 12, in <module>
from .adapters import SSLAdapter, SourceAddressAdapter
File "/usr/lib/python3.6/site-packages/requests_toolbelt/adapters/__init__.py", line 12, in <module>
from .ssl import SSLAdapter
File "/usr/lib/python3.6/site-packages/requests_toolbelt/adapters/ssl.py", line 16, in <module>
from .._compat import poolmanager
File "/usr/lib/python3.6/site-packages/requests_toolbelt/_compat.py", line 51, in <module>
from urllib3.contrib import appengine as gaecontrib
ImportError: cannot import name 'appengine'
I have just installed requests_toolbelt in cygwin on Windows:
$ pip3 install requests-toolbelt
Collecting requests-toolbelt
Downloading https://files.pythonhosted.org/packages/97/8a/d710f792d6f6ecc089c5e55b66e66c3f2f35516a1ede5a8f54c13350ffb0/requests_toolbelt-0.8.0-py2.py3-none-any.whl (54kB)
100% |████████████████████████████████| 61kB 841kB/s
Requirement already satisfied: requests<3.0.0,>=2.0.1 in /usr/lib/python3.6/site-packages (from requests-toolbelt)
Requirement already satisfied: urllib3==1.20 in /usr/lib/python3.6/site-packages (from requests<3.0.0,>=2.0.1->requests-toolbelt)
Installing collected packages: requests-toolbelt
Successfully installed requests-toolbelt-0.8.0
You are using pip version 9.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Also note that I am running behind proxy.
I am running python 3.6.4:
$ python3
Python 3.6.4 (default, Jan 7 2018, 15:53:53)
[GCC 6.4.0] on cygwin
Considering all these, I am not sure why I am getting this error. Is it like requests_toolbelt have dependency appengine which is not installed? But it would have been installed while installing requests_toolbelt, right?
Update
I was getting above error when I am running the python file in eclipse with PyDev plugin. However I just tried running the same line through python shell >>> in cygwin command prompt and its giving same error.
Update 2
Tried installing same on python under Windows (not on cygwin) and it worked:
C:\Users\user1>pip install requests-toolbelt
Collecting requests-toolbelt
Downloading https://files.pythonhosted.org/packages/97/8a/d710f792d6f6ecc089c5e55b66e66c3f2f35516a1ede5a8f54c13350ffb0/requests_toolbelt-0.8.0-py2.py3-none-any.whl (54kB)
100% |████████████████████████████████| 61kB 1.7MB/s
Collecting requests<3.0.0,>=2.0.1 (from requests-toolbelt)
Downloading https://files.pythonhosted.org/packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl (91kB)
100% |████████████████████████████████| 92kB 1.9MB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests<3.0.0,>=2.0.1->requests-toolbelt)
Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 2.4MB/s
Collecting urllib3<1.24,>=1.21.1 (from requests<3.0.0,>=2.0.1->requests-toolbelt)
Downloading https://files.pythonhosted.org/packages/bd/c9/6fdd990019071a4a32a5e7cb78a1d92c53851ef4f56f62a3486e6a7d8ffb/urllib3-1.23-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 2.4MB/s
Collecting certifi>=2017.4.17 (from requests<3.0.0,>=2.0.1->requests-toolbelt)
Downloading https://files.pythonhosted.org/packages/7c/e6/92ad559b7192d846975fc916b65f667c7b8c3a32bea7372340bfe9a15fa5/certifi-2018.4.16-py2.py3-none-any.whl (150kB)
100% |████████████████████████████████| 153kB 1.5MB/s
Collecting idna<2.8,>=2.5 (from requests<3.0.0,>=2.0.1->requests-toolbelt)
Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)
100% |████████████████████████████████| 61kB 1.4MB/s
Installing collected packages: chardet, urllib3, certifi, idna, requests, requests-toolbelt
Successfully installed certifi-2018.4.16 chardet-3.0.4 idna-2.7 requests-2.19.1 requests-toolbelt-0.8.0 urllib3-1.23
You are using pip version 9.0.2, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\user1>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from requests_toolbelt.multipart.encoder import MultipartEncoder
>>>
Still guessing why it was not working on cygwin.

This seems to be an issue in requests_toolbelt which might be fixed in 0.7.1.
Try to install newest version of it.
https://github.com/mvantellingen/python-zeep/issues/413

Related

Python isn't registering the new module from pip install

I recently installed the requests library for python. And python does not see it, however it is installed
Console output:
C:\Users\Raitis\Desktop>pip3 install requests
Requirement already satisfied: requests in c:\users\raitis\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (2.23.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\raitis\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from requests) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\raitis\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from requests) (2019.11.28)
Requirement already satisfied: idna<3,>=2.5 in c:\users\raitis\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from requests) (2.9)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\raitis\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from requests) (3.0.4)
C:\Users\Raitis\Desktop>py
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
It is installed indeed, and we can see that in direcory(Screenshot:https://prnt.sc/r90uhr) and python's path is added to the enviroment PATH(Screenshot: https://prnt.sc/r90rus)
Try installing the request library using this command instead
py -m pip install requests
Or in your case use,
py -m pip3 install requests

Python3 ERROR:no module named telebot after pip installed it

python 3.5.2 // Ubuntu 16.04 LTS
I've installed pyTelegramBotAPI to code bots for telegram using this command:
pip instal pyTelegramBotAPI
Result:
Collecting pyTelegramBotAPI
Requirement already satisfied: six in /home/username/.local/lib/python2.7/site-packages (from pyTelegramBotAPI) (1.11.0)
Collecting requests (from pyTelegramBotAPI)
Using cached https://files.pythonhosted.org/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests->pyTelegramBotAPI)
Using cached https://files.pythonhosted.org/packages/7c/e6/92ad559b7192d846975fc916b65f667c7b8c3a32bea7372340bfe9a15fa5/certifi-2018.4.16-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests->pyTelegramBotAPI)
Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests->pyTelegramBotAPI)
Using cached https://files.pythonhosted.org/packages/27/cc/6dd9a3869f15c2edfab863b992838277279ce92663d334df9ecf5106f5c6/idna-2.6-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests->pyTelegramBotAPI)
Using cached https://files.pythonhosted.org/packages/63/cb/6965947c13a94236f6d4b8223e21beb4d576dc72e8130bd7880f600839b8/urllib3-1.22-py2.py3-none-any.whl
Installing collected packages: certifi, chardet, idna, urllib3, requests, pyTelegramBotAPI
Then, I imported it into my source code:
import telebot
However, when I run the code I get the following error:
Traceback (most recent call last):
File "firstBot.py", line 1, in <module>
import telebot
ImportError: No module named 'telebot'
It mostly happens for Linux Users, because there is a preinstalled python(version 2.x) in the shell, When you install a new module or run your app with default python, it runs and serves by python2.x.
You should use pip3 when you installing it, or run your app by python3 app_main_file.py

matplotlib 1.3.1 has requirement numpy>=1.5, but you'll have numpy 1.8.0rc1 which is incompatible

I'm executing bellow command in Mac (High Sierra) as a part of getting started with pyAudioAnalysis.
pip install numpy matplotlib scipy sklearn hmmlearn simplejson eyed3 pydub
I'm getting following error during the installation process. Appreciate your input.
matplotlib 1.3.1 has requirement numpy>=1.5, but you'll have numpy 1.8.0rc1 which is incompatible.
Please find more information below,
Channas-MacBook-Pro:~ channa$ python
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
[3]+ Stopped python
Channas-MacBook-Pro:~ channa$ pip -V
pip 10.0.0b2 from /Library/Python/2.7/site-packages/pip-10.0.0b2-py2.7.egg/pip (python 2.7)
Channas-MacBook-Pro:~ channa$ sudo pip install numpy matplotlib scipy sklearn hmmlearn simplejson eyed3 pydub
The directory '/Users/channa/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/channa/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (1.8.0rc1)
Requirement already satisfied: matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (1.3.1)
Requirement already satisfied: scipy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (0.13.0b1)
Collecting sklearn
Downloading sklearn-0.0.tar.gz
Collecting hmmlearn
Downloading hmmlearn-0.2.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (183kB)
100% |████████████████████████████████| 184kB 189kB/s
Collecting simplejson
Downloading simplejson-3.13.2.tar.gz (79kB)
100% |████████████████████████████████| 81kB 256kB/s
Collecting eyed3
Downloading eyeD3-0.8.5-py2.py3-none-any.whl (167kB)
100% |████████████████████████████████| 174kB 100kB/s
Collecting pydub
Downloading pydub-0.21.0-py2.py3-none-any.whl
Requirement already satisfied: python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) (1.5)
Collecting tornado (from matplotlib)
Downloading tornado-5.0.1.tar.gz (504kB)
100% |████████████████████████████████| 512kB 354kB/s
Requirement already satisfied: pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) (2.0.1)
Collecting nose (from matplotlib)
Downloading nose-1.3.7-py2-none-any.whl (154kB)
100% |████████████████████████████████| 163kB 213kB/s
Collecting scikit-learn (from sklearn)
Downloading scikit_learn-0.19.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (8.0MB)
100% |████████████████████████████████| 8.0MB 259kB/s
Collecting python-magic (from eyed3)
Downloading python_magic-0.4.15-py2.py3-none-any.whl
Collecting pathlib (from eyed3)
Downloading pathlib-1.0.1.tar.gz (49kB)
100% |████████████████████████████████| 51kB 54kB/s
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from eyed3) (1.4.1)
Collecting futures (from tornado->matplotlib)
Downloading futures-3.2.0-py2-none-any.whl
Collecting singledispatch (from tornado->matplotlib)
Downloading singledispatch-3.4.0.3-py2.py3-none-any.whl
Collecting backports_abc>=0.4 (from tornado->matplotlib)
Downloading backports_abc-0.5-py2.py3-none-any.whl
matplotlib 1.3.1 has requirement numpy>=1.5, but you'll have numpy 1.8.0rc1 which is incompatible.
Installing collected packages: scikit-learn, sklearn, hmmlearn, simplejson, python-magic, pathlib, eyed3, pydub, futures, singledispatch, backports-abc, tornado, nose
Running setup.py install for sklearn ... done
Running setup.py install for simplejson ... done
Running setup.py install for pathlib ... done
Running setup.py install for tornado ... done
Consider using the `--user` option or check the permissions
I was able to solve this with #Jacob's solution with some additional steps. I'll post it here for anyone else facing this.
Firstly as Jacob mentioned I downloaded and installed the latest Python 2.7.14+.
Executed sudo easy_install pip to install pip again
Executed sudo pip install numpy
Download the latest version of Python 2.7 (https://www.python.org/downloads/), matplotlib install should work fine after that.
Also if it's a brand new mac, just make sure that you have command line tools installed

Issues importing python-pptx on Linux (Ubuntu 17)

I am trying to import the python pptx library in a python programm. I installed it using pip before, which gave me the following output:
Collecting python-pptx
Downloading python-pptx-0.6.6.tar.gz (8.4MB)
100% |████████████████████████████████| 8.4MB 132kB/s
Collecting Pillow>=2.6.1 (from python-pptx)
Downloading Pillow-4.2.1-cp27-cp27mu-manylinux1_x86_64.whl (5.8MB)
100% |████████████████████████████████| 5.8MB 193kB/s
Collecting XlsxWriter>=0.5.7 (from python-pptx)
Downloading XlsxWriter-0.9.8-py2.py3-none-any.whl (137kB)
100% |████████████████████████████████| 143kB 1.2MB/s
Collecting lxml>=3.1.0 (from python-pptx)
Downloading lxml-3.8.0-cp27-cp27mu-manylinux1_x86_64.whl (6.8MB)
100% |████████████████████████████████| 6.8MB 166kB/s
Collecting olefile (from Pillow>=2.6.1->python-pptx)
Downloading olefile-0.44.zip (74kB)
100% |████████████████████████████████| 81kB 1.3MB/s
Building wheels for collected packages: python-pptx, olefile
Running setup.py bdist_wheel for python-pptx ... done
Stored in directory: /home/clemens/.cache/pip/wheels/27/f8 /dc/181ed5439001413ee0c1c8794a06009c4c0b96f652401e2d20
Running setup.py bdist_wheel for olefile ... done
Stored in directory: /home/clemens/.cache/pip/wheels/20/58 /49/cc7bd00345397059149a10b0259ef38b867935ea2ecff99a9b
Successfully built python-pptx olefile
Installing collected packages: olefile, Pillow, XlsxWriter, lxml, python-pptx
Successfully installed Pillow-4.2.1 XlsxWriter-0.9.8 lxml-3.8.0 olefile-0.44 python-pptx-0.6.6
So this seems to be a success.
But as I am trying to import the module using the following code:
try:
from pptx import Presentation
except Exception as e:
print(e)
It says No module named 'pptx'.
It must have something to do with Linux since the same code works just fine on windows and the module seems to be installed correctly. I am using Python 3.5.3.
Using pip install, you'll install it for Python2, not for Python3. To make sure it gets installed for Python3, invoke pip from the interpreter, like this:
python3 -m pip install <package>

How to import installed Python module?

I've just installed a Python package using pip:
$ sudo pip install py_vollib
Password:
Collecting py_vollib
Downloading py_vollib-1.0.1.tar.gz
Collecting py_lets_be_rational (from py_vollib)
Downloading py_lets_be_rational-1.0.1.tar.gz
Requirement already satisfied: simplejson in /Library/Python/2.7/site-packages (from py_vollib)
Requirement already satisfied: numpy in /Library/Python/2.7/site-packages (from py_vollib)
Collecting pandas (from py_vollib)
Downloading pandas-0.20.3-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (15.0MB)
100% |████████████████████████████████| 15.1MB 54kB/s
Requirement already satisfied: scipy in /Library/Python/2.7/site-packages (from py_vollib)
Requirement already satisfied: pytz>=2011k in /Library/Python/2.7/site-packages (from pandas->py_vollib)
Requirement already satisfied: python-dateutil in /Library/Python/2.7/site-packages (from pandas->py_vollib)
Requirement already satisfied: six>=1.5 in /Library/Python/2.7/site-packages (from python-dateutil->pandas->py_vollib)
Installing collected packages: py-lets-be-rational, pandas, py-vollib
Running setup.py install for py-lets-be-rational ... done
Running setup.py install for py-vollib ... done
Successfully installed pandas-0.20.3 py-lets-be-rational-1.0.1 py-vollib-1.0.1
and I've verified it's installed correctly:
$ pip freeze | grep vollib
py-vollib==1.0.1
but I can't import it in Python:
$ python
Python 2.7.13 (default, Jul 20 2017, 18:14:09)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import py_vollib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named py_vollib
Does anybody know what I'm doing wrong here?
[EDIT]
I've checked out help('modules'), which also shows the py_vollib package:
you are doing sudo pip install py_vollib which is installing the library in your root env.
If you are doing import py_vollib in ipython notebook or something, the module won't be available.
Try sudo python and then do the import
Or
do pip install py_vollib and then do python and try import py_vollib

Categories

Resources