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)
sudo apt install tells the operating system to install apps/programs. pip3 doesn't relate to the operating system, but is a package installer for python.
Never use sudo to install with pip. This is the same as running a virus as root. Either add your local folder to your PATH or use a virtualenv. Save this answer.
They do exactly the same thing. In fact, the docs for distributing Python modules were just updated to suggest using python -m pip instead of the pip executable, because it's easier to tell which version of python is going to be used to actually run pip that way.
pip is used to download and install packages directly from PyPI. PyPI is hosted by Python Software Foundation. It is a specialized package manager that only deals with python packages. apt-get is used to download and install packages from Ubuntu repositories which are hosted by Canonical.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With