点击卸载工作,但给出错误

时间:2016-06-16 10:29:09

标签: python python-3.x pip virtualenv pypi

我已下载,构建并安装了示例pypi项目。该项目应该用于深入了解python包装,并在Python Packaging User GuidePackaging and Distributing Projects中引用。因此,我很困惑为什么在按照他们关于创建包的说明进行操作时,我在卸载它时会出错。

如上所述,我使用了他们的示例项目。如果有人可以解释一下,我们将不胜感激。

主要提示:我正在运行Mac OSX,我安装的python版本是3.5.1 以下是重现问题的步骤:

mkdir testdirectory 
cd testdirectory/
pyvenv venv    # Creating a virtual environment
source venv/bin/activate
git clone https://github.com/pypa/sampleproject.git    # Getting sample project
cd sampleproject/
python setup.py build
python setup.py install    # Installing on the virtual environment

pip list
peppercorn (0.5)
pip (7.1.2)
sample (1.2.0)
setuptools (18.2)

pip uninstall sample

导致以下输出:

Uninstalling sample-1.2.0:
  /Users/steve/testdirectory/venv/bin/sample
  /Users/steve/testdirectory/venv/lib/python3.5/site-packages/sample-1.2.0-py3.5.egg
Proceed (y/n)? y
  Successfully uninstalled sample-1.2.0
Traceback (most recent call last):
  File "/Users/steve/testdirectory/venv/bin/pip3", line 11, in <module>
    sys.exit(main())
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/__init__.py", line 217, in main
    return command.main(cmd_args)
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/basecommand.py", line 248, in main
    pip_version_check(session)
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/utils/outdated.py", line 102, in pip_version_check
    installed_version = get_installed_version("pip")
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/utils/__init__.py", line 858, in get_installed_version
    working_set = pkg_resources.WorkingSet()
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 629, in __init__
    self.add_entry(entry)
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 685, in add_entry
    for dist in find_distributions(entry, True):
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2075, in find_eggs_in_zip
    if metadata.has_metadata('PKG-INFO'):
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1605, in has_metadata
    return self.egg_info and self._has(self._fn(self.egg_info, name))
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1963, in _has
    return zip_path in self.zipinfo or zip_path in self._index()
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1843, in zipinfo
    return self._zip_manifests.load(self.loader.archive)
  File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1783, in load
    mtime = os.stat(path).st_mtime
FileNotFoundError: [Errno 2] No such file or directory: '/Users/steve/testdirectory/venv/lib/python3.5/site-packages/sample-1.2.0-py3.5.egg'

看起来软件包已正确卸载,但仍然会抛出错误。

2 个答案:

答案 0 :(得分:6)

记录在案:

$ pip help uninstall

Usage:
  pip uninstall [options] <package> ...
  pip uninstall [options] -r <requirements file> ...

Description:
  Uninstall packages.

  pip is able to uninstall most installed packages. Known exceptions are:

  - Pure distutils packages installed with ``python setup.py install``, which
    leave behind no metadata to determine what files were installed.
  - Script wrappers installed by ``python setup.py develop``.

即。您收到错误是因为您没有使用pip本身进行安装 - 您使用了setup.py,所以pip并不知道安装了什么。

答案 1 :(得分:0)

安装包不是python setup.py install而是pip install .

然后卸载将正常运行