加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 使用pip的问题,(异常[…] findall()只需要2个参数(给

发布时间:2020-12-20 13:39:44 所属栏目:Python 来源:网络整理
导读:我找不到任何类似这个问题的东西. 每当我尝试使用pip时,我都会遇到此异常(以Scrapy为例): C:Python27Scriptspip-script.py run on 01/16/14 16:26:32Requirement already satisfied (use --upgrade to upgrade): Scrapy in c:python27libsite-package
我找不到任何类似这个问题的东西.

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

C:Python27Scriptspip-script.py run on 01/16/14 16:26:32
Requirement already satisfied (use --upgrade to upgrade): Scrapy in c:python27libsite-packagesscrapy-0.20.2-py2.7.egg
Requirement already satisfied (use --upgrade to upgrade): Twisted>=10.0.0 in c:python27libsite-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:userstobiasappdatalocaltemppip_build_Tobias...
Exception:
Traceback (most recent call last):
  File "c:python27libsite-packagespipbasecommand.py",line 122,in main
    status = self.run(options,args)
  File "c:python27libsite-packagespipcommandsinstall.py",line 270,in run
    requirement_set.prepare_files(finder,force_root_egg_info=self.bundle,bundle=self.bundle)
  File "c:python27libsite-packagespipreq.py",line 1157,in prepare_files
    url = finder.find_requirement(req_to_install,upgrade=self.upgrade)
  File "c:python27libsite-packagespipindex.py",line 264,in find_requirement
    page_versions.extend(self._package_versions(page.links,req.name.lower()))
  File "c:python27libsite-packagespipindex.py",line 440,in _package_versions
    for link in self._sort_links(links):
  File "c:python27libsite-packagespipindex.py",line 430,in _sort_links
    for link in links:
  File "c:python27libsite-packagespipindex.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

解决方法

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

By default,the document will be an xml.etree element instance. Whenever possible,html5lib chooses the accelerated ElementTree implementation (i.e. xml.etree.cElementTree on Python 2.x).

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

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

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

您可以尝试转到命令提示符并尝试导入xml.etree并导入elementtree.如果他们都工作分别尝试帮助(xml.etree)和帮助(elementtree).检查DESCRIPTION部分中给出的构建日期.如果你有一个非常古老的(2008年之前)元素树构建并且没有具体原因 – 那么卸载它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读