0

*Thought it would be more appropriate to ask in Ask Ubuntu rather than in Stack Overflow.

Using Ubuntu16.04, I am working with python2 (along with some scientific modules) for scientific purposes and decided to switch to python3, and to my understanding; I would need to install the packages again, this time for python3.
As I am a beginner, I especially worry about not removing the packages properly (I would actually prefer to purge them), and of course, not installing the packages properly.

How can I make this transition clean? More specifically I would like to:

  1. Remove all packages I installed with pip (which are connected to python2).
  2. Install anew the packages, this time for python3.

For 1. Searching online I came up with

pip freeze | xargs pip uninstall -y

Which should remove the packages I installed, but is it possible to purge?.

For 2. Does it mean I need to install pip3? When installing packages or updating with pip i would get a call:

The directory '/home/.../.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/.../.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Figuring I might have installed something improperly. What should i do differently?

Zanna
  • 69,223
  • 56
  • 216
  • 327
Ranc
  • 143
  • 6
  • 1
    It's not necessary to uninstall packages from pip2 just to work now with the same package versions installed with pip3. They won't interfere with each other and you might maybe accidentally remove something that is needed by anything else. Just leave it as it is, it shouldn't do any harm. For the future, you might want to look into virtualenvs (virtual environments) that allow you to have completely separate and independent Python environments inside which you can work without affecting the system's Python installation or the virtualenvs of other projects. – Byte Commander Nov 16 '16 at 20:54
  • 1
    The warning you describe about `~/.cache/pip` not being owned by the current user can simply be avoided by using `sudo -H pip3 ...` instead of just `sudo pip3 ...` as mentioned in the warning itself. The `-H` flag tells `sudo` to use the target (root) user's home directory instead of the invoking (your) home directory. That way pip3 will store its cache files over there and you don't have problems with them. – Byte Commander Nov 16 '16 at 20:56
  • 1
    Oh, and yes, to be able to use pip to manage packages for Python 3, you must install the apt package `python3-pip` first. (`sudo apt-get install python3-pip`) After that you should ideally always specify the version number of the pip you use, like `pip2` and `pip3` instead of plain `pip`. Normally if you only use the apt packages, plain `pip` will always default to `pip2`, but once you upgrade the pips using themselves (which is required in some cases) this is no longer guaranteed. – Byte Commander Nov 16 '16 at 21:00
  • @ByteCommander, I am actually looking forward to remove the 'heavier' packages such as spyder saving space and making a cleaner system without multiplicities. Should I use pip to uninstall them? (Thought I might aswell remove all). – Ranc Nov 16 '16 at 21:20

0 Answers0