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?
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?
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:
path/to/venv/bin/python -m pip install SomeProjectpath\to\venv\Scripts\python.exe -m pip install --upgrade pipBut 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).
python -m pip"It's the same thing.
python3 -m pip install calls pip as a module in python, while pip install calls pip directly.
The only reason to prefer the first is that in order to use the second you need to have set pip in your environmental variables (for Windows). In older versions of python this was not done automatically during installation, rather you had to do this manually. That's why in a lot of guides you might see them using the first syntax for their instructions (because it works always, as long as you have python3 in your environmental variables. For Linux/Mac operating systems there isn't any difference.