How to install pip with Python 3?

后端 未结 21 1252
夕颜
夕颜 2020-11-22 01:06

I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2.

How can I install pip with Python 3?

21条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 01:44

    Single Python in system

    To install packages in Python always follow these steps:

    1. If the package is for python 2.x: sudo python -m pip install [package]
    2. If the package is for python 3.x: sudo python3 -m pip install [package]

    Note: This is assuming no alias is set for python

    Through this method, there will be no confusion regarding which python version is receiving the package.

    Multiple Pythons

    Say you have python3 ↔ python3.6 and python3.7 ↔ python3.7

    1. To install for python3.6: sudo python3 -m pip install [package]
    2. To instal for python3.7: sudo python3.7 -m pip install [package]

    This is essentially the same method as shown previously.

    Note 1

    How to find which python, your python3 command spawns:

    ganesh@Ganesh:~$ python3 # Type in terminal
    Python 3.6.6 (default, Sep 12 2018, 18:26:19) # Your python3 version
    [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

    Notice python 3.6.6 in the second line.

    Note 2

    Change what python3 or python points to: https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3

提交回复
热议问题