sudo pip install setuptools --upgrade error

时间:2016-05-03 05:55:30

标签: python-2.7

我正在做pip install setuptools --upgrade,但收到错误

Installing collected packages: setuptools
  Found existing installation: setuptools 1.1.6
    Uninstalling setuptools-1.1.6:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_set.py", line 726, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_install.py", line 746, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 299, in move
    copytree(src, real_dst, symlinks=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 208, in copytree
    raise Error, errors
Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', "[Errno 1] Operation not permitted: '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', "[Errno 1] Operation not permitted: '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', "[Errno 1] Operation not permitted: '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib'")]

我错过了什么?我也试过sudo pip install,但没有帮助。

2 个答案:

答案 0 :(得分:20)

尝试手动升级:

pip uninstall setuptools
pip install setuptools

如果它不起作用,请尝试:     pip install --upgrade setuptools --user python

如您所见,该操作没有获得适当的权限:

[Errno 1] Operation not permitted: '/tmp/pip-rV15My-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc'")

答案 1 :(得分:1)

我遇到了类似的问题但是有不同的错误和不同的分辨率。 (我在这里找到了一个解决方案,所以我在这里发布我的详细信息以防万一。)

TL; DR:如果Python虚拟环境中的升级setuptools似乎有效,但报告OSError: [Errno 2] No such file or directory,请尝试在继续之前停用并重新激活虚拟环境,例如:

    source myenv/bin/activate
    pip install --upgrade setuptools
    deactivate
    source myenv/bin/activate
     :

长版

我正在为长期运行的项目升级Python版本和库。我使用python虚拟环境进行开发和测试。主机系统是MacOS 10.11.5(El Capitan)。我发现在创建虚拟环境后需要更新pip(显然是由于最近的pypa TLS更改截至2018-04),所以我的初始设置看起来像这样(已安装)使用可下载的MacOS安装程序的最新版本的Python 2.7系列:

    virtualenv myenv -p python2.7
    source myenv/bin/activate
    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
    python get-pip.py

到目前为止,非常好:)当我尝试运行时出现问题:

    pip install --upgrade setuptools

安装似乎工作正常,但后来我收到一条错误消息,因此:

    Collecting setuptools
      Using cached setuptools-39.0.1-py2.py3-none-any.whl
    Installing collected packages: setuptools
      Found existing installation: setuptools 0.6rc11
        Uninstalling setuptools-0.6rc11:
          Successfully uninstalled setuptools-0.6rc11
    Successfully installed setuptools-39.0.1
    Traceback (most recent call last):
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/bin/pip", line 11, in <module>
        sys.exit(main())
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/__init__.py", line 248, in main
        return command.main(cmd_args)
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/basecommand.py", line 252, in main
        pip_version_check(session)
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/utils/outdated.py", line 102, in pip_version_check
        installed_version = get_installed_version("pip")
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/utils/__init__.py", line 838, in get_installed_version
        working_set = pkg_resources.WorkingSet()
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 644, in __init__
        self.add_entry(entry)
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 700, in add_entry
        for dist in find_distributions(entry, True):
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1949, in find_eggs_in_zip
        if metadata.has_metadata('PKG-INFO'):
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1463, in has_metadata
        return self.egg_info and self._has(self._fn(self.egg_info, name))
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1823, in _has
        return zip_path in self.zipinfo or zip_path in self._index()
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1703, in zipinfo
        return self._zip_manifests.load(self.loader.archive)
      File "/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1643, in load
        mtime = os.stat(path).st_mtime
    OSError: [Errno 2] No such file or directory: '/Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg'

请注意,安装似乎已成功完成,然后是OSError异常,这似乎是尝试访问旧的setuptools。尽管有错误消息,pip似乎可以正常安装新包,但我的本地setup.py无法找到它的依赖项; e.g:

    $ python setup.py install
    running install
      :
     (lots of build messages)
      :
    Installed /Users/graham/workspace/github/gklyne/annalist/anenv/lib/python2.7/site-packages/oauth2client-1.2-py2.7.egg
    Processing dependencies for oauth2client==1.2
    Searching for httplib2>=0.8
    Reading https://pypi.python.org/simple/httplib2/
    Couldn't find index page for 'httplib2' (maybe misspelled?)
    Scanning index of all packages (this may take a while)
    Reading https://pypi.python.org/simple/
    No local packages or working download links found for httplib2>=0.8
    error: Could not find suitable distribution for Requirement.parse('httplib2>=0.8')

但是如果我使用pip来安装相同的依赖项('httplib2&gt; = 0.8'),它运行正常,我可以毫无问题地重新运行setup.py

此时我猜测运行setup.pypip之间的区别在于虚拟环境以某种方式挂在某些旧的setuptools文件上,但是pip有自己的副本。因此,在升级setuptools并获取OSError: [Errno 2] No such file or directory消息后,我将停用并重新激活虚拟环境,因此:

    deactivate
    source myenv/bin/activate

中提琴setup.py似乎工作正常!