How to fix ImportError: no module named packages.urllib3?

I am running Python 2.7.6 on an Ubuntu machine. When I run twill-sh (Twill is the browser used to test sites) in my terminal, I get the following:

 Traceback (most recent call last): File "dep.py", line 2, in <module> import twill.commands File "/usr/local/lib/python2.7/dist-packages/twill/__init__.py", line 52, in <module> from shell import TwillCommandLoop File "/usr/local/lib/python2.7/dist-packages/twill/shell.py", line 9, in <module> from twill import commands, parse, __version__ File "/usr/local/lib/python2.7/dist-packages/twill/commands.py", line 75, in <module> browser = TwillBrowser() File "/usr/local/lib/python2.7/dist-packages/twill/browser.py", line 31, in __init__ from requests.packages.urllib3 import connectionpool as cpl ImportError: No module named packages.urllib3 

However, I can import urllib into the Python console just fine. What could be the reason?

+8
python urllib2 urllib3 twill
source share
3 answers

There is a difference between standard urllib and urllib2 and third-party urllib3 .

Twill doesn't seem to install dependencies, so you need to do it yourself. Twill is dependent on the requests library that comes with and uses urllib3 backstage. You also need the lxml and cssselect .

You can install them on the terminal as follows:

pip install requests

pip install lxml

and

pip install cssselect

+13
source share

If you already have β€œqueries” installed from the default assembly, you may need to

sudo pip install --upgrade requests

Credit @bkzland from the comment on the previous answer:

I followed these steps with the same error, I needed to use sudo pip install --upgrade every time to get it working. - bkzland Dec 17 '15 at 12:57

--- Now, how do I make this dependency in my setup.py?

+17
source share

If you have an aroma based on RHEL, then:

yum install -y python-requests

Debian / Ubuntu:

apt-get install -y python-requests

Linux based arches:

pacman -S python-requests

+4
source share

All Articles