本文介绍了如何修复ImportError:没有名为packages.urllib3的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Ubuntu机器上运行Python 2.7.6.当我在终端中运行twill-sh(Twill是用于测试网站的浏览器)时,得到以下信息:

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 <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

但是,我可以在Python控制台中导入urllib.可能是什么原因?

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

推荐答案

标准urlliburllib2与第三方urllib3之间存在区别.

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

看起来斜纹纸不会安装依赖项,因此您必须自己做.斜纹依赖于附带的requests库,并且在后台使用urllib3.您还需要lxmlcssselect库.

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

pip install cssselect

这篇关于如何修复ImportError:没有名为packages.urllib3的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:24