sudo pip install setuptools --upgrade error

后端 未结 2 1078
[愿得一人]
[愿得一人] 2021-01-04 07:29

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

Installing collected packages: setuptools
  Found existing installation: set         


        
2条回答
  •  隐瞒了意图╮
    2021-01-04 08:20

    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 
            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!

提交回复
热议问题