简体   繁体   中英

What is the difference between installing packages with Python 3 and pip3 in terminal?

I have two versions of Python on my Mac: 2.7 and 3.8.

When installing packages, I use pip3 instead of pip in order for the packages so install for the correct Python version.

However, I noticed that I can also install with Python3 in the terminal:

 python3 -m pip install ...

Is there a difference between the two? I noticed they showed different pip versions which was a bit strange.

https://docs.python.org/3/using/cmdline.html#cmdoption-m

Using -m is another way of executing an installed module. More specifically, it would be a way of using modules installed for different python versions.

python2 -m pip install ...
python3 -m pip install ...

Run flask module installed on python2 or python3
python2 -m flask
python3 -m flask

For your case you probably want to install a module on python 3.8 as 2.7 is the default installation that comes with the OS and not somewhere you'd want to install modules for development.

python -m pip install... is the same as using pip, but pip3 is for python3. The only thing you need to change is "python" to "python3" like this: python3 -m pip install...

Edit: python3 is used when running scripts with python 3.8, while "python" is with python 2.7. pip3 is mainly if you want the libraries installed for python3, and you don't really care about 2.7.

This is what you need to know:

In short:

Always use the path/to/pythonX.Y -m pip somecommand form, known as the executable module (or executable package ). Never use the script form pip , pip3 , or anything like that, because there is no guarantee which Python interpreter is associated with a script (unless you actually have everything under control and check yourself).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM