3

I have two Ubuntu servers. Entering the 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:

What’s 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

Server B has the file located here, so it should find it:

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Prometheus
  • 32,405
  • 54
  • 166
  • 302
  • [Did you install `requests`, using `pip` or `easy_install`?](http://stackoverflow.com/questions/17309288/importerror-no-module-named-requests#comment25103544_17309288) – Bhargav Rao Sep 25 '15 at 10:14
  • @BhargavRao installed using pip. – Prometheus Sep 25 '15 at 10:18
  • Be sure you dont have a script named `requests.py` on that folder in server B – Assem Sep 25 '15 at 10:19
  • In the same folder of server B, execute `>>> import requests >>> requests.__path__` and tell us what you have as output – Assem Sep 25 '15 at 10:24
  • @bigOTHER gives ``['/usr/lib/python2.7/dist-packages/requests']`` should it not be ``/usr/local/lib/python2.7/`` – Prometheus Sep 25 '15 at 10:25
  • Looks like the sys.path is in the wrong order. can this be changed? – Prometheus Sep 25 '15 at 10:32
  • Its ok with `/usr/lib/python2.7/dist-packages`. you can change the order, it's a `list`, so you can manipulate it – Assem Sep 25 '15 at 10:36
  • Would this be permanent? – Prometheus Sep 25 '15 at 10:39
  • @Falcon1 not permanent; why not just use urllib3 directly like: `from urllib3.poolmanager import PoolManager` – Assem Sep 25 '15 at 10:40
  • Thats what I'm trying to do ``from urllib3.poolmanager import PoolManager`` but it looks like it finding an other version in ``/usr/lib/python2.7/dist-packages/requests`` which does not ship with urllib3 – Prometheus Sep 25 '15 at 10:44

1 Answers1

4

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:

  1. Use urllib3 directly:

     from urllib3.poolmanager import PoolManager
    
  2. 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Assem
  • 11,574
  • 5
  • 59
  • 97
  • Option 2 how can I remove the version from /usr/lib/python2.7/dist-packages/requests? pip uninstall removes it from the wrong one. – Prometheus Sep 25 '15 at 10:49
  • 1
    If it was installed via apt-get, try : `sudo apt-get remove python-requests` , else just remove the folder. – Assem Sep 25 '15 at 10:52