Azure / msrest-for-python

The runtime library "msrest" for AutoRest generated Python clients.
MIT License
41 stars 64 forks source link

[Debian/Ubuntu] ImportError: No module named packages.urllib3 #3

Closed derekbekoe closed 7 years ago

derekbekoe commented 7 years ago

If a user has the Debian version of requests, they may run into the following error.

  File "/home/ls/.local/lib/python2.7/site-packages/msrest/__init__.py", line 27, in <module>
    from .configuration import Configuration
  File "/home/ls/.local/lib/python2.7/site-packages/msrest/configuration.py", line 39, in <module>
    from .pipeline import (
  File "/home/ls/.local/lib/python2.7/site-packages/msrest/pipeline.py", line 36, in <module>
    from requests.packages.urllib3 import Retry
ImportError: No module named packages.urllib3

Observations:

Not 100% sure of the following but I suspect that this may be a cause. Even if I do have the pip version of requests (which includes `requests.packages....), I may still run into this error if I also have the Debian package installed. Based on how Python loads modules from PATH, the Debian package in /dist-packages might get loaded instead of the pip package in /site-packages.

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)

/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
/home/debekoe/.local/lib/python2.7/site-packages
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages

Is the solution to try the import requests.packages.urllib3, if it fails, fall back to urllib3....?

Reference links:

derekbekoe commented 7 years ago

cc: @johanste