使用pip的问题,(Exception [...] findall()只需要2个参数(给定3个)

时间:2014-01-16 15:55:48

标签: python pip

我找不到任何类似这个问题的东西。

每当我尝试使用pip时,我都会遇到此异常(以Scrapy为例):

C:\Python27\Scripts\pip-script.py run on 01/16/14 16:26:32
Requirement already satisfied (use --upgrade to upgrade): Scrapy in c:\python27\lib\site-packages\scrapy-0.20.2-py2.7.egg
Requirement already satisfied (use --upgrade to upgrade): Twisted>=10.0.0 in c:\python27\lib\site-packages (from Scrapy)
Downloading/unpacking w3lib>=1.2 (from Scrapy)
  Getting page https://pypi.python.org/simple/w3lib/
  URLs to search for versions for w3lib>=1.2 (from Scrapy):
  * https://pypi.python.org/simple/w3lib/
  Analyzing links from page https://pypi.python.org/simple/w3lib/
Cleaning up...
  Removing temporary dir c:\users\tobias\appdata\local\temp\pip_build_Tobias...
Exception:
Traceback (most recent call last):
  File "c:\python27\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "c:\python27\lib\site-packages\pip\commands\install.py", line 270, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "c:\python27\lib\site-packages\pip\req.py", line 1157, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "c:\python27\lib\site-packages\pip\index.py", line 264, in find_requirement
    page_versions.extend(self._package_versions(page.links, req.name.lower()))
  File "c:\python27\lib\site-packages\pip\index.py", line 440, in _package_versions
    for link in self._sort_links(links):
  File "c:\python27\lib\site-packages\pip\index.py", line 430, in _sort_links
    for link in links:
  File "c:\python27\lib\site-packages\pip\index.py", line 772, in links
    for anchor in self.parsed.findall(".//a"):
TypeError: findall() takes exactly 2 arguments (3 given)

我正在使用Windows 7 32位,Python 2.7

1 个答案:

答案 0 :(得分:1)

我认为你的元素树有一个糟糕的版本。在pip中,self.parsed应该是html5lib.parse从包中的HTML页面返回的html5lib解析树对象。 readme for html5lib说:

  

默认情况下,文档将是xml.etree元素实例。只要有可能,html5lib就会选择加速的ElementTree实现(即Python 2.x上的xml.etree.cElementTree)。

This question在不同的上下文中描述了类似的问题,并且在评论中隐藏,我们看到OP通过不同地导入ElementTree解决了这个问题。我想你已经以某种方式获得了一些不兼容的版本,可能是cElementTree,html5lib tries to use if it can

我建议卸载elementtree(如果它存在于任何site-packages目录中,并且你没有具体的原因)。如果这不起作用,则pip的完全卸载/重新安装似乎是最佳选择。

测试问题(不是严格的答案部分)

您可以尝试转到命令提示符并尝试import xml.etreeimport elementtree。如果它们都有效,请分别尝试help(xml.etree)help(elementtree)。检查DESCRIPTION部分中给出的构建日期。如果您有一个非常古老的(2008年之前)elementtree版本,并且没有具体原因 - 那么请将其卸载。