Issue
I always use pip install
(which I think is equivalent to pip3 install
since I only have python3 in my env) to install packages. But I recently heard python3 -m pip install
is better. Why?
Solution
I would advise against ever calling any pip somecommand
(or pip3
) script directly. Instead it's much safer to call pip's executable module for a specific Python interpreter explicitly, something of the form path/to/pythonX.Y -m pip somecommand
.
There are many advantages to this, for example:
- It is explicit for which Python interpreter the projects will be pip-installed (Python 2 or 3, inside the virtual environment or not, etc.)
- For a virtual environment, one can pip-install (or do other things) without activating it:
path/to/venv/bin/python -m pip install SomeProject
- Under Windows this is the only way to safely upgrade pip itself
path\to\venv\Scripts\python.exe -m pip install --upgrade pip
But yes, if all is perfectly setup, then python3 -m pip install SomeProject
and pip3 install SomeProject
should do the exact same thing, but there are way too many cases where there is an issue with the setup and things don't work as expected and users get confused (as shown by the many questions about this topic on this platform).
References
- Brett Cannon's article "Why you should use
python -m pip
" - pip's documentation section on "Upgrading pip"
- venv's documentation section on "Creating virtual environments": "You don’t specifically need to activate an environment [...]"
Answered By - sinoroc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.