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

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

I'm running Python 2.7.6 on an Ubuntu machine. When I run twill-sh (Twill is a browser used for testing websites) in my Terminal, I'm getting the following:

Traceback (most recent call last):   File "dep.py", line 2, in      import twill.commands   File "/usr/local/lib/python2.7/dist-packages/twill/__init__.py", line 52, in      from shell import TwillCommandLoop   File "/usr/local/lib/python2.7/dist-packages/twill/shell.py", line 9, in      from twill import commands, parse, __version__   File "/usr/local/lib/python2.7/dist-packages/twill/commands.py", line 75, in      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 in Python console just fine. What could be the reason?

回答1:

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

It looks like twill does not install the dependencies so you have to do it yourself. Twill depends on requests library which comes with and uses urllib3 behind the scenes. You also need lxml and cssselect libraries.

You can install them on terminal as follows:

pip install requests

pip install lxml

and

pip install cssselect



回答2:

If you already have 'requests' installed from a default build, you may have to

sudo pip install --upgrade requests

Credit to @bkzland from comment on previous answer:

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



回答3:

If you are having a RHEL based flavour, then:

yum install -y python-requests

Debian/Ubuntu based flavour:

apt-get install -y python-requests

Arch Linux based flavour:

pacman -S python-requests



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!