Ubuntu – Preventing pip from removing system packages during upgrade

package-managementpythonupgrade

I have a fairly straightforward Ubuntu (13.04) desktop installation, which comes complete with several Ubuntu-packaged Python utilities — these live in /usr/lib/python2.7 and are owned by root. I call these "system" Python packages.

I also do a lot of scientific work with Python and so I have installed tools like numpy, matplotlib, etc. using pip — these live in /usr/local/lib/python2.7 and are owned by me (I chowned /usr/local because I'm the only user on this machine). I call these "local" Python packages. I put the local path in front of the system one in my PYTHONPATH so that I load local packages preferentially.

Now, I'm trying to upgrade one of the local packages that I installed using pip, and pip is failing because it wants to uninstall a dependent system package as part of the upgrade process.

I have two questions about this, addressing the problem from each end :

One way to fix this problem is to get pip to upgrade my local packages and ignore the system-installed ones (if possible). Can I prevent pip from trying to uninstall a system package during a local package upgrade, but only for one dependency ?

Another way would be to have pip install a newer version of the package, and then use that version to satisfy dependencies in apt related tools. Is there a way to tell Ubuntu that a pip-installed package will satisfy an apt dependency ?

(I am familiar with virtualenv, but on this machine I only ever use this one environment, so I'd really like to avoid keeping track of whether I'm working in the correct virtualenv.)

Best Answer

If you do not want pip to install or uninstall any dependencies you can use

pip install --no-deps package_name

Be ware that you are in that case responsible for making sure the different dependencies needed for the package you install are satisfied.

To use it when upgrading a package use:

pip install -U --no-deps package_name

For a similar problem, cf. Drag forward installed Python packages when upgrading

Related Question