9

I tried installing Flask and a few packages using sudo in a virtual environment, but on trying to import Flask, it'll throw up an ImportError. On installing the same packages with pip install though it works fine. So what's the difference between these methods? I tried this on Ubuntu.

Also, where does pip install these packages? Looking through Stack Overflow I could only find questions that answer how to list packages installed by pip, but not where to find them (in context to the virtual environment)

Projjol
  • 909
  • 2
  • 10
  • 20
  • 2
    `pip install` installs as the user you are currently logged in as. `sudo pip install` installs as the root user – inspectorG4dget Oct 11 '15 at 18:46
  • 2
    Usually the system packages are installed without write privileges for normal users so you must use `sudo` to elevate the privilege so `pip` can install to system packages. You can install a local copy of packages, ideally using `virtualenv`, where you wouldn't need elevated privileges. – AChampion Oct 11 '15 at 19:00
  • 1
    Related: [Is it acceptable & safe to run pip install under sudo?](http://stackoverflow.com/q/15028648/95735), [What are the risks of running 'sudo pip'?](http://stackoverflow.com/q/21055859/95735) – Piotr Dobrogost Apr 04 '17 at 17:11

1 Answers1

7
pip install

Will run pip install as the current user


sudo pip install

Will run pip install with the security privileges of another user, root for example.
You normally need to use sudo to install a package on a system.


You may want to read linux-101-introduction-to-sudo

Pedro Lobito
  • 75,541
  • 25
  • 200
  • 222