pylint3 和 pip3 损坏

pylint3 和 pip3 损坏

我试过sudo apt remove --purge各种软件包。重新安装后,得到的结果都一样。

我也尝试过使用 aptitude 重新安装。但这不起作用。

我目前的解决方法是以 root 身份运行 pylint3,这可行,但却是不好的做法。

pip3

    $ pip3
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
    __import__(vendored_name, globals(), locals(), level=0)
ImportError: No module named 'pip._vendor.pkg_resources'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 13, in <module>
    from pip.exceptions import InstallationError, CommandError, PipError
  File "/usr/lib/python3/dist-packages/pip/exceptions.py", line 6, in <module>
    from pip._vendor.six import iteritems
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 75, in <module>
    vendored("pkg_resources")
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
    __import__(modulename, globals(), locals(), level=0)
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2927, in <module>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2913, in _call_aside
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 956, in subscribe
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in <lambda>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2515, in activate
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2097, in declare_namespace
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2047, in _handle_ns
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2066, in _rebuild_mod_path
AttributeError: '_NamespacePath' object has no attribute 'sort'

pylint3

$ pylint3
Traceback (most recent call last):
  File "/usr/bin/pylint3", line 3, in <module>
    run_pylint()
  File "/usr/lib/python3/dist-packages/pylint/__init__.py", line 22, in run_pylint
    from pylint.lint import Run
  File "/usr/lib/python3/dist-packages/pylint/lint.py", line 44, in <module>
    import astroid
  File "/usr/lib/python3/dist-packages/astroid/__init__.py", line 54, in <module>
    from astroid.nodes import *
  File "/usr/lib/python3/dist-packages/astroid/nodes.py", line 54, in <module>
    from astroid.scoped_nodes import (
  File "/usr/lib/python3/dist-packages/astroid/scoped_nodes.py", line 35, in <module>
    from astroid import manager
  File "/usr/lib/python3/dist-packages/astroid/manager.py", line 29, in <module>
    from astroid import modutils
  File "/usr/lib/python3/dist-packages/astroid/modutils.py", line 40, in <module>
    import pkg_resources
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2927, in <module>
    @_call_aside
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2913, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 956, in subscribe
    callback(dist)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2952, in <lambda>
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2515, in activate
    declare_namespace(pkg)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2097, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2047, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2066, in _rebuild_mod_path
    orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'

更新 这解决了问题。 sudo apt remove --purge python3-setuptools 我很想知道如何解决。

更新 更新 我重新安装了所需的依赖项。然后问题又出现了。

@Kenavera 我使用的是来自 repo 的最新 python3-tools(根据 synaptic python3-tools 20.7.0-1,它似乎相当旧了)。

以我的身份运行 python3,因为 root 下的 pylint3 正在运行。我仍然想要一个更好的解决方案。

答案1

清理 Python 安装 将 Python 安装恢复为默认安装,并添加 apt 包依赖项

列出通过 apt 手动安装的所有内容:

comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)

删除 pylint3 和所有 python3-*。对我来说这是:

sudo apt remove pylint3 python3-googleapi python3-lxml python3-matplotlib python3-numpy python3-pip python3-pyocr python3-scipy python3-tk python-lxml python-numpy python-pip python-setuptools

sudo apt autoremove

列出通过 pip 安装的内容ls -ltd /usr/local/lib/python3.5/dist-packages/*

删除它们

pip3 uninstall setuptools
pip3 uninstall pydicom
pip3 uninstall docx

最后是 pip 本身

pip3 uninstall pip

通过从此处删除所有内容来删除为用户安装的所有内容

'$HOME/.local/lib/python*'

重新安装

sudo apt install python3-pip pylint3 python3-venv

设置虚拟环境

我有一个名为 plan-report 的项目。在那个目录中(不是以 root 身份)

python3 -m venv plan-report-env
chmod +x ./plan-report-env/bin/activate

# this line needs repeating each time a terminal is opened
./plan-report-env/bin/activate

在虚拟环境中重新安装 python 包。例如

pip install numpy

请注意,是 python3 创建了 venv,所以现在您只需说pip,而不是pip3。在 venv 中升级 pip 似乎也可以。

pip install --upgrade pip

答案2

sudo apt-get upgrade python-setuptools对我来说很管用。希望这对你也有帮助。

相关内容