Python下Pip安装包下的AttributeError: 'Requirement' object has no attribute 'project_name'

来源:互联网 发布:遗传算法原理与应用 编辑:程序博客网 时间:2024/06/01 09:57

引言: 在基于pip安装第三方依赖库的过程中,会碰到AttributeError: 'Requirement' object has no attribute 'project_name'的错误信息,这个问题该如何解决呢?


1.  问题的提出

    在某开源系统的调试中,需要安装一批依赖包,其使用一个requirements.txt来描述其所有的依赖包,具体如下:  

...................HTTPReplay==0.1.5idna==2.0ipaddress==1.0.14itsdangerous==0.24Jinja2==2.8jsbeautifier==1.5.10Mako==1.0.1MarkupSafe==0.23ndg-httpsclient==0.4.0pyasn1==0.1.8pycparser==2.14.................................
  基于pip进行安装:
sudo pip install -r requirements.txt
  在安装过程中,出现来如下错误信息:
Exception:Traceback (most recent call last):  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main    status = self.run(options, args)  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 317, in run    requirement_set.prepare_files(finder)  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files    ignore_dependencies=self.ignore_dependencies))  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 448, in _prepare_file    req_to_install, finder)  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 387, in _check_skip_installed    req_to_install.check_if_exists()  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 1011, in check_if_exists    self.req.project_nameAttributeError: 'Requirement' object has no attribute 'project_name'

2.问题的分析

   第一步首先单独进行安装特定包的检查:

   >> sudo pip install six==1.9.0

 

polo@polo-notebook:/opt/cuckoo$ sudo pip install six==1.9.0The directory '/home/polo/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.The directory '/home/polo/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.Exception:Traceback (most recent call last):  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main    status = self.run(options, args)  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 317, in run    requirement_set.prepare_files(finder)  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files    ignore_dependencies=self.ignore_dependencies))  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 448, in _prepare_file    req_to_install, finder)  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 387, in _check_skip_installed    req_to_install.check_if_exists()  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 1011, in check_if_exists    self.req.project_nameAttributeError: 'Requirement' object has no attribute 'project_name'

问题依然存在,看来问题就出在这个安装包这里。是否是由于版本太老呢?接下来继续尝试。

 >>  sudo pip install six

polo@polo-notebook:/opt/cuckoo$ sudo pip install sixThe directory '/home/polo/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.The directory '/home/polo/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packagesYou are using pip version 8.1.1, however version 8.1.2 is available.You should consider upgrading via the 'pip install --upgrade pip' command.
这里反馈的信息是six包已经被安装过了,难道是由于系统已经安装的six版本不兼容问题?

  让我们来查看一下six当下的版本:

polo@polo-notebook:/opt/cuckoo$ pip show six---Metadata-Version: 2.0Name: sixVersion: 1.10.0Summary: Python 2 and 3 compatibility utilitiesHome-page: http://pypi.python.org/pypi/six/Author: Benjamin PetersonAuthor-email: benjamin@python.orgInstaller: pipLicense: MITLocation: /usr/local/lib/python2.7/dist-packagesRequires: Classifiers:  Programming Language :: Python :: 2  Programming Language :: Python :: 3  Intended Audience :: Developers  License :: OSI Approved :: MIT License  Topic :: Software Development :: Libraries  Topic :: UtilitiesYou are using pip version 8.1.1, however version 8.1.2 is available.You should consider upgrading via the 'pip install --upgrade pip' command.
原来的确如此,要安装的版本低于目前系统的版本,故爆出来了如此诡异的错误信息。

3. 总结

在pip管理下的包在升级和安装过程中,project_name的问题时常发生,大部分的情况下都是版本的不兼容问题造成的,尤其在第三方项目强调特定版本的依赖包情况下,也可以通过卸载当下版本,安装需要的版本;但是这样也给我们的系统带来来若干隐患问题,低版本的安装包与当下系统中其他版本的兼容问题。

0 0
原创粉丝点击