13

I am doing pip install setuptools --upgrade but getting error below

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'")]

What am I missing? I tried sudo pip install also but didn't help.

nad
  • 2,640
  • 11
  • 55
  • 96
  • Please delete that whole output and re-add it using **code formatting** (the **`{}`**-button in your question editor or CTRL+K), it's horribly hard to read without formatting (and the blockquote-button you used already destroyed the original structure) – Byte Commander May 03 '16 at 06:05

2 Answers2

24

Try to upgrade manually:

pip uninstall setuptools
pip install setuptools

If it doesn't work, try: pip install --upgrade setuptools --user python

As you can see, the operation didn't get appropriate privilege:

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

qtopierw
  • 1,447
  • 14
  • 23
1

I ran into a similar problem but with a different error, and different resolution. (My search for a solution led me here, so I'm posting my details here in case it helps.)

TL;DR: if upgrading setuptools in a Python virtual environment appears to work, but reports OSError: [Errno 2] No such file or directory, try deactivating and reactivating the virtual environment before continuing, e.g.:

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

Long version

I'm in the process of upgrading Python version and libraries for a long-running project. I use a python virtual environment for development and testing. Host system is MacOS 10.11.5 (El Capitan). I've discovered that pip needs to be updated after the virtual environment is created (apparently due to some recent pypa TLS changes as of 2018-04), so my initial setup looks like this (having installed the latest version of the Python 2.7 series using the downloadable MacOS installer):

    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

So far, so good :) My problem comes when I try to run:

    pip install --upgrade setuptools

The installation appears to work OK, but then I get an error message, thus:

    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'

Note that the installation appears to complete successfully, followed by the OSError exception, which appears to be an attempt to access the old setuptools. Despite the error message, pip seems to work just fine for installing new packages, but my local setup.py fails to find its dependencies; 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')

But if I use pip to install the same dependency ('httplib2>=0.8'), it works fine, and I can re-run setup.py without any problems.

At this point I'm guessing that the difference between running setup.py and pip is that the virtual environment is somehow hanging onto some old setuptools files, but pip comes with its own copy. So after upgrading setuptools and getting the OSError: [Errno 2] No such file or directory message, I deactivate and reactivate the virtual environment, thus:

    deactivate
    source myenv/bin/activate

and, viola, setup.py seems to work fine!

Graham Klyne
  • 816
  • 10
  • 16