No module named for requests - python

I have two Ubuntu servers. Entering below on server Server A works fine:
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> from requests.packages.urllib3.poolmanager import PoolManager
Server B however,
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> from requests.packages.urllib3.poolmanager import PoolManager
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named packages.urllib3.poolmanager
Both have the same version:
Name: requests
Version: 2.7.0
Location: /usr/local/lib/python2.7/dist-packages
Requires:
Whats going on here?
Here is Server B's paths:
/usr/local/lib/python2.7/dist-packages/greenlet-0.4.5-py2.7-linux-x86_64.egg
/usr/local/lib/python2.7/dist-packages/gevent-1.0.1-py2.7-linux-x86_64.egg
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
Thing is the Sever B has the file located here so it should find it:
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3

It's an issue in python-requests as the owners did not package it the same between Pypi and Ubuntu repository as mentioned here.
Solutions:
Use urllib3 directly:
from urllib3.poolmanager import PoolManager
Remove completely all copies of python-requests than re-install it either using pip or using apt-get, the one that includes packages.urllib3 inside.

Related

pypy no module named dateutil

I'm trying to import dateutil in pypy, which I've got the following error. Importing dateutil in python2.7 didn't return an error
[root#]# python
Python 2.7.5 (default, May 31 2018, 09:41:32)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dateutil
>>> exit()
[root#]# pypy
Python 2.7.13 (4a68d8d3d2fc1faec2e83bcb4d28559099092574, Oct 18 2019, 01:09:48)
[PyPy 7.2.0 with GCC 8.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> import dateutil
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named dateutil
I'm not sure if this is related but dateutil is found in
/usr/lib/python2.7/site-packages
But not found in
/usr/lib64/python2.7/site-packages
pypy on the server is located in
/opt/pypy-7.2.0-linux_x86_64-portable
I tried uninstalling dateutil and reinstalling dateutil using pip, but pypy can't seem to find it.
Would appreciate any help. Thank you in advance!!!
You might be using the wrong pip. When you call pip install ... you will find whichever pip is first on your $PATH, which may not be the one you need. I try to use path/to/pypy -mpip install ... which will ensure you are using the correct one

Running “import tensorflow” on Mac generates "No module named tensorflow" error

Actually I already installed tensorflow by using
$ pip install tensorflow
and it works well when I use
$ python
Python 2.7.15 (default, Jul 23 2018, 21:27:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>import tensorflow
>>>
but when I use python3 on command line
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
>>>
it shows an error, and it shows the same error when I use IDLE
use
pip3 install tensorflow
pip installs to default python directory. pip3 installs to python3

Googleapiclient and python3

I wrote a basic Python 3 script that uses the Google Sheets API. It works on a system that defaults to Python 3 (Arch). I'm trying to run the same script on an Ubuntu 14.04 system, but I'm unable to load the apiclient library. I installed with the recommended
pip install --upgrade google-api-python-client
But I noticed I can only load the library in python 2.
Here's what I'm observing:
~ $ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from googleapiclient import discovery
>>> quit()
~ $ python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from googleapiclient import discovery
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'googleapiclient'
Any advice?
The Googleapiclient is installed only on python2 (Which i guess is your default python version) not python3.
Install Googleapiclient in python3 env using the following:
pip3 install --upgrade google-api-python-client
python -m pip install --upgrade google-api-python-client

ImportError: No module named pycurl - developing an OpenStack Horizon Plugin

I'm developing an openstack horizon plugin that should poll some info via a ReST API. I'm following this tutorial: http://docs.openstack.org/developer/horizon/topics/tutorial.html
So in the file /opt/stack/horizon/openstack_dashboard/dashboards/mydashboard/mypanel/views.py I have:
from horizon import tabs
from horizon import views
from openstack_dashboard.dashboards.mydashboard.mypanel import tabs as mydashboard_tabs
import sys
import pycurl
Resulting in ImportError: No module named pycurl
If I load python and check, pycurl is loadable:
oink#ubuntu14-devstack:/opt/stack/horizon/openstack_dashboard/dashboards/mydashboard/templates/mydashboard/mypanel$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycurl
>>> pycurl
<module 'pycurl' from '/usr/lib/python2.7/dist-packages/pycurl.so'>
OpenStack is running python version 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2], which matches my line interpreter. How would I be able to use pycurl in an OpenStack Horizon view? (Or, what is a good mechanism to poll a ReST API from Horizon?)
Virtualenv is in the way?
Meanwhile I'm using this hack:
import sys
sys.path.append("/usr/lib/python2.7/dist-packages")
import pycurl

Python, Ubuntu: Install PyPi package for a specific Python version

I've installed Python 3.3 alongside Python 2.75 on my Ubuntu machine. The problem is that easy_install gets packages for the default, 2.75 version only, e.g:
easy_install pymongo
$ python
Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>>
But:
$ python3.3
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'pymongo'
How can I install PyPi packages for the Python 3.3 installation?
You need easy_install3. In apt-get you get it by
apt-get install python3-setuptools

Categories