0

I would like to install the newest version of docutils via pip, but it can't figure out how to upgrade the system version installed via apt.

$ sudo --set-home python2 -m pip install --upgrade docutils
Collecting docutils
  Using cached https://files.pythonhosted.org/packages/3a/dc/bf2b15d1fa15a6f7a9e77a61b74ecbbae7258558fcda8ffc9a6638a6b327/docutils-0.15.2-py2-none-any.whl
Installing collected packages: docutils
  Found existing installation: docutils 0.14
ERROR: Cannot uninstall 'docutils'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

$ apt-cache show python-docutils | head -n 3
Package: python-docutils
Architecture: all
Version: 0.14+dfsg-3

None of the solutions I've thought of or found on the web appeal:

  1. Delete the apt version with rm -rf /usr/lib/python2.7/dist-packages/docutils*. This silences pip but means:

    • Installed files on the system no longer match what the Debian packaging system thinks
    • I might break dependencies of system software on docutils 0.14
    • Any updates to the Debian package will cause apt to reinstall
    • Other problems discussed in this answer
  2. pip install --force-reinstall. (Same problems.)

  3. pip install --ignore-install. (Same problems.)

Is there a way to get a default environment that works for me with the newest versions of stuff from pip but has no chance of breaking any system software? The same answer above suggests using one of virtualenv, venv, pyenv, pipenv. I tried pipenv and it doesn't want to install individual packages listed on the commandline using --system and I don't know whether creating a Pipfile will actually solve this problem.

I would rather not have to manually switch environments somehow to use the apt-installed packages versus the pip-installed packages. Is there a way to get only apt-installed software to use one environment and otherwise use the environment with the pip-installed stuff?

Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86
  • 2
    Most likely the version installed by apt is used by other apps or even worse the system, you should try to modify this install. The good practice is to have multiple version in parallel which should be done with virtualenv or equivalent. Note: `pip install --user docutils` might work, but i would recommend using a virtualenv. – Taek Aug 06 '19 at 16:15

2 Answers2

2

I would rather not have to manually switch environments somehow to use the apt-installed packages versus the pip-installed packages. Is there a way to get only apt-installed software to use one environment and otherwise use the environment with the pip-installed stuff?

Ideally, one should use either the system version or the pip version.

Per the Debian Python Policy,

As long as you don't install other versions of Python in your path, Debian's Python versions won't be affected by a new version.

If you install a different micro version of the version of Python you have got installed, you will need to be careful to install all the modules you use for that version of Python too.

Community
  • 1
  • 1
oxr463
  • 1,573
  • 3
  • 14
  • 34
0

So far adding the following to ~/.bashrc seems work well:

if [ ! -d ~/venv/python3 ]; then
    python3 -m venv --system-site-packages ~/venv/python3
fi

if [ -d ~/venv/python3 ]; then
    VIRTUAL_ENV_DISABLE_PROMPT=1 . ~/venv/python3/bin/activate
fi

Most of the system-installed scripts have one of the Pythons in /usr/bin hard-coded instead of using /usr/bin/env python so they are unaffected by this.

Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86
  • 1
    Use of virtual environments is the right way. I find it a bit kludgy, but nonetheless it works. I have begun using a "default" system-wide venv for the one-off scripts and creating app-specific venv per larger, more-structured applications. – JGurtz Aug 06 '19 at 22:20