2

Going around I read a lot about how sudo pip is a very bad habit/solution. Some reasons people gave were:

  • It could run malicious code.
  • It will break permission structs.
  • Sudo is used to install a package "system wide".
  • It is Satan!1!!one

An alternative I found is running pip with --user (e.g. pip install --user package). I saw that python in Debian works a little different (I have Stretch), mostly because of path used (--user is standard in Debian if omitted, btw). In conclusion, I found a lot of inconsistent things.

Taking for granted that using sudo and pip together are wrong, can someone explain me why, and most of all, when is it wrong? Major issues I encountered were all about permissions, so my guess is that sudo "just" ruin ownership.

Are there any other solutions besides using --user or virtualenv?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
ingroxd
  • 995
  • 1
  • 12
  • 28
  • @Rawing if I had to guess, because this question has been asked and answered many times before, and a quick Google search reveals that. – vaultah Nov 13 '17 at 15:53
  • Thanks for the edits! Anyway I already read the posts flagged as duplicated and they were the exact reason that pushed me to ask the question: in one post the answer is "because of ownership", in another is "because you run code from internet", another says "because of scope visibility"... – ingroxd Nov 13 '17 at 16:10
  • @vaultah Thanks, it seems my google-fu has failed me... I wasn't able to find any particularly useful information about this topic with a quick search. – Aran-Fey Nov 13 '17 at 17:03

1 Answers1

3

Unless you want or have to install a binary, service or dependency globally, you would not want to use sudo pip. As you surmise correctly, it installs your dependency globally, and this may cause inconsistencies while developing.

The more conventional thing to do nowadays is to use a virtualenv with which to install your dependencies. This way, anything you do with installation is local to that specific virtualenv instance of Python.

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • Tried to edit to correct spelling, but I would have to edit more than 6 characters. Your link for `virtualenv` is mispelled. Also, it is worth adding that to use a virtual environment, simply `source /path/to/my/venv/bin/activate` and then you can use pip to install most packages just as you normally would. – slightlynybbled Nov 13 '17 at 15:47
  • The location is correct, the letters aren't... you wrote `virutalenv` when it should be `virtualenv` – slightlynybbled Nov 13 '17 at 15:57