0

I have tried sudo apt remove --purge on various packages. I get the same when I reinstall.

I have also tried reinstall using aptitude. This does not work.

My current workaround is to run pylint3 as root, which works, but is bad practice.

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'

update This fixed it. sudo apt remove --purge python3-setuptools I would love to understand how.

update update I re-installed dependencies that I need. Then the problem cam back.

@Kenavera I am at the newest python3-tools from the repo (according to synaptic python3-tools 20.7.0-1, which seems quite old).

running python3 as me, as pylint3 at root is working. I still would like a better solution.

2 Answers2

1

Clean up python installation Restore Python installation to default plus apt package dependencies

list all things manually installed via apt:

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

remove pylint3 and all python3-*. For me this was:

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

list things installed via pip ls -ltd /usr/local/lib/python3.5/dist-packages/*

remove them

pip3 uninstall setuptools
pip3 uninstall pydicom
pip3 uninstall docx

lastly pip itself

pip3 uninstall pip

delete everything installed for the user by deleting all from here

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

Reinstall

sudo apt install python3-pip pylint3 python3-venv

Set up virtual environment

I have a project called plan-report. in that directory (not as 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

reinstall python packages in the virtual environment. eg

pip install numpy

Note that it was python3 that created the venv, so now you just say pip, not pip3. seems ok to upgrade pip within the venv too.

pip install --upgrade pip

0

sudo apt-get upgrade python-setuptools did the trick for me. Hope this helps you too.

  • 1
    Nice too see you have solved it. I found my source after your follow up question in: https://github.com/pypa/pip/issues/4216

    There it is stated that: ... the problem arose when Setuptools 31 introduced support for setup.py develop on namespace packages, which required the expansion of -nspkg.pth files. This change essentially meant that older versions of pkg_resources didn't support this new format and would choke. and this seems to be also applicable to your command.

    – Kenavera Feb 24 '18 at 09:26