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


11

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
sudo pip install -U pip setuptools
AB

@AB只是尝试这样做,发现它不会覆盖OS版本...这可能是问题..
斯图尔特轴突

Answers:


18
  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-setuptoolspython-pip将这些软件包带回的软件包,因此您可能必须重复此过程!


也可以在centos上工作
Abhishek Dujari

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


1
我接受了AB的答案,因为这是大部分答案,但是如果我能接受两者的话,我会的。-我还没有机会尝试此操作,因为自从升级Ubuntu以来,对在其上安装setuptools感到有点疑惑,我可能需要在虚拟机中尝试一下,看看会发生什么。
斯图尔特·阿克森
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.