点列表引发ValueError

时间:2019-02-01 20:25:07

标签: python pip

我无法使用/usr/local/lib/python3.6/dist-packages/pip(python 3.6)中的pip 19.0.1运行$ pip list

$ pip list
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2584, in version
    return self._version
  File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2691, in __getattr__
    raise AttributeError(attr)
AttributeError: _version

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 176, in main
    status = self.run(options, args)
  File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/list.py", line 148, in run
    self.output_package_listing(packages, options)
  File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/list.py", line 205, in output_package_listing
    data, header = format_for_columns(packages, options)
  File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/list.py", line 271, in format_for_columns
    row = [proj.project_name, proj.version]
  File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2589, in version
    raise ValueError(tmpl % self.PKG_INFO, self)
ValueError: ("Missing 'Version:' header and/or METADATA file", Unknown [unknown version] (/usr/local/lib/python3.6/dist-packages))

我正在运行这些命令的新虚拟机上运行,​​最后一个命令安装了我从github克隆的内容。

apt-get install -y python3 python3-pip python3-dev
python3 -m pip install --upgrade pip
pip3 install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz#egg=en_core_web_sm-2.0.0
sudo -H pip3 install -e /vagrant

2 个答案:

答案 0 :(得分:0)

问题是我的Python库中有以连字符开头的文件夹,这些文件夹会导致错误。我不确定将其重命名为什么,所以我删除了它们。将来可能会导致我遇到问题,但已解决了该线程的问题。

假设有问题的文件夹名为-bad_folder。这些命令可以解决该问题:

cd /usr/local/lib/python3.6/dist-packages
rm -rf ./-bad_folder

错误文件夹名称前的./很重要,因此命令行可以识别出它是文件而不是命令的选项。

如果有比删除文件夹更好的解决方案,请告诉我。

更新:我带有前导连字符的文件夹名为-pacy;看来这是spaCy(Python软件包)安装不完整的产物。我给了我的VM更多的内存,然后再次安装它,而-pacy文件不存在。

答案 1 :(得分:-1)

pip命令通常引用Python版本2。

改为尝试pip3