如何在 ubuntu 15.04 上升级 python setuptools > 12.2

如何在 ubuntu 15.04 上升级 python setuptools > 12.2

apt 包好像是 12.2

如果我运行, sudo pip install -U setuptools 版本似乎仍然停留在 12.2

$ python
>>> import pkg_resources
>>> r = pkg_resources.require(["setuptools"])[0]
>>> print("setuptools version: %s" % r.version)
setuptools version: 12.2

[编辑]

刚刚注意到它不会覆盖 setuptools 的操作系统版本:

Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-7.1.2-py2.py3-none-any.whl#md5=5ff9fec0be479e4e36df467556deed4d
  Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB): 1.1MB downloaded
Downloading/unpacking setuptools from https://pypi.python.org/packages/3.4/s/setuptools/setuptools-18.3.2-py2.py3-none-any.whl#md5=58c1e15fe0c124ab0880a2691f232434
  Downloading setuptools-18.3.2-py2.py3-none-any.whl (462kB): 462kB downloaded
Installing collected packages: pip, setuptools
  Found existing installation: pip 1.5.6
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, owned by OS
  Found existing installation: setuptools 12.2
    Not uninstalling setuptools at /usr/lib/python2.7/dist-packages, owned by OS
Successfully installed pip setuptools
Cleaning up...

[/编辑]

答案1

  1. 删除存储库版本

    sudo apt-get remove python-setuptools
    
  2. 如果需要,pip再次安装

    wget https://bootstrap.pypa.io/get-pip.py
    sudo -H python get-pip.py
    
  3. setuptools通过安装pip

    sudo -H pip install -U pip setuptools
    

现在,重新开始测试

% python
Python 2.7.9 (default, Apr  2 2015, 15:33:21) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> r = pkg_resources.require(["setuptools"])[0]
>>> print("setuptools version: %s" % r.version)
setuptools version: 18.3.2

笔记

安装任何依赖于或的包python-setuptools都会python-pip使这些包恢复,因此您可能必须重复此过程!

答案2

AB 提出的解决方案可能还不够:在最新版本的 setuptools 中pkg_resources是一个包,而以前它只是一个模块。

setuptools按照所述方式更新将留下陈腐pkg_resources.py{,c},这可能会导致导入时出现以下错误setuptools

AttributeError: 'module' object has no attribute 'packaging'

要删除它,请执行以下操作:

  1. 找出过时的pkg_resources模块位于何处:

    $ python -c 'import pkg_resources; print(pkg_resources.__file__)'
    /usr/lib/python2.7/dist-packages/pkg_resources.pyc
    
  2. 删除此文件及其.py文件:

    $ sudo rm /usr/lib/python2.7/dist-packages/pkg_resources.py*
    

警告

此文件可能已通过python-pkg-resources软件包安装。因此,更新或重新安装此软件包将恢复过时的模块!还请注意,您正在干扰一个本应由 控制的文件apt

相关内容