1

I was testing CARLA, a self-driving car simulator on ubuntu 16.04.5 LTS last year and at that time, I had installed pygame. At that time pygame had been installed under /usr/lib/python2.7/dist-packages/pygame and I had fixed a file there to make it work right. Now, recently I re-installed ubuntu 16.04.5 LTS for the machine (only the OS part) and tried testing CARLA and found I have to install pygame(which is of course). So I did pip install pygame(without sudo) and CARLA now works again.
But soon I found the location of pygame installation is now not /usr/lib/python2.7/dist-packages/pygame but ~/.local/lib/python2.7/site-packages/pygame.
Why is it installed in my local home directory, not in the system directory? (I tried installing it with sudo, but it says Requirement alread satisfied.)
I tried python -m pip uninstall pip but received message below.

 Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
You are using pip version 8.1.1, however version 19.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

should I do pip upgrade?
ADD : This question is not about 'sudo' or 'apt install'. Normally in apt install, if we omit sudo, it asks for root priviledge and doesn't install it. But pip installs it under ~/.local. Therefore this question is different from suggested duplicate question.

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • 1
    Possible duplicate of [What is the difference between pip install and sudo pip install?](https://stackoverflow.com/questions/33068758/what-is-the-difference-between-pip-install-and-sudo-pip-install) – tripleee Feb 13 '19 at 07:56
  • Did this or my answer clarify your original question? – hyperTrashPanda Feb 14 '19 at 13:58
  • @hyperTrashPanda yes, thanks! (I was busy after selecting your choice and checking it's correct). – Chan Kim Feb 15 '19 at 06:57

1 Answers1

0

First, python -m pip uninstall pip is meant to uninstall pip, not pygame, so you wouldn't want to do that.

When invoked with sudo, pip will install the libraries system-wide on /usr/lib, so they're accessible by all users.

When called without sudo and/or with a --user flag, they're installed for your user only on your home directory. In either case, pip reports the library as already installed, and doesn't need to re-install it. Take a look at the link provided by triplee, as well as here

You can use the following, to verify that Python looks at both of these paths to find available libraries.

import sys
print(sys.path)

To address your point, both of these locations are fine, it just a matter of preference.

If you want to uninstall pygame from ~/.local you should try pip uninstall pygame, and then use sudo pip install pygame again, to have a system-wide, static version installation.

In my opinion, it's better to have user dependencies gathered locally, so that each user is free to install/remove/update libraries and modules to his requirements, and preferably inside his Virtual Environment.

hyperTrashPanda
  • 838
  • 5
  • 18
  • 1
    Hi, Thanks!. Correct. I didn't know for pip, if we omit 'sudo' it installs under ~/.local. Usually, when we use install using `apt install`, it asks for root priviledge and doesn't install, which is different from pip behavior. That's what I was not aware of. – Chan Kim Feb 15 '19 at 06:58
  • Glad your question was answered! – hyperTrashPanda Feb 15 '19 at 07:12
  • 1
    now I uninstalled pygame in ~/.local and then I installed it with `sudo` and it's now installed in /usr/local. – Chan Kim Feb 16 '19 at 10:10