How to install pip with Python 3?

后端 未结 21 1275
夕颜
夕颜 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 02:02

    For Ubuntu 12.04 or older,

    sudo apt-get install python3-pip
    

    won't work. Instead, use:

    sudo apt-get install python3-setuptools ca-certificates
    sudo easy_install3 pip
    
    0 讨论(0)
  • 2020-11-22 02:04

    What’s New In Python 3.4

    ...

    pip should always be available

    ...

    By default, the commands pipX and pipX.Y will be installed on all platforms (where X.Y stands for the version of the Python installation), along with the pip Python package and its dependencies.

    https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-453

    so if you have python 3.4 installed, you can just: sudo pip3 install xxx

    0 讨论(0)
  • 2020-11-22 02:04

    For python3 try this:

    wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
    

    The good thing is that It will also detect what version of python you have (even if it's an environment of python in your custom location). After this you can proceed normally with (for example)

    pip install numpy
    

    source: https://pypi.python.org/pypi/setuptools/1.1.6#upgrading-from-setuptools-0-6

    0 讨论(0)
  • 2020-11-22 02:04

    And for Windows 8.1/10 OS Users just open cmd (command prompt)

    write this : C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts

    then

    just write this : pip3 install {name of package}

    Hint: the location of folder Python36-32 may get different for new python 3.x versions

    0 讨论(0)
  • 2020-11-22 02:06

    edit: Manual installation and use of setuptools is not the standard process anymore.

    If you're running Python 2.7.9+ or Python 3.4+

    Congrats, you should already have pip installed. If you do not, read onward.

    If you're running a Unix-like System

    You can usually install the package for pip through your package manager if your version of Python is older than 2.7.9 or 3.4, or if your system did not include it for whatever reason.

    Instructions for some of the more common distros follow.

    Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 2.x

    Run the following command from a terminal:

    sudo apt-get install python-pip 
    

    Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 3.x

    Run the following command from a terminal:

    sudo apt-get install python3-pip
    
    Note:

    On a fresh Debian/Ubuntu install, the package may not be found until you do:

    sudo apt-get update
    

    Installing pip on CentOS 7 for Python 2.x

    On CentOS 7, you have to install setup tools first, and then use that to install pip, as there is no direct package for it.

    sudo yum install python-setuptools
    sudo easy_install pip
    

    Installing pip on CentOS 7 for Python 3.x

    Assuming you installed Python 3.4 from EPEL, you can install Python 3's setup tools and use it to install pip.

    # First command requires you to have enabled EPEL for CentOS7
    sudo yum install python34-setuptools
    sudo easy_install pip
    

    If your Unix/Linux distro doesn't have it in package repos

    Install using the manual way detailed below.

    The manual way

    If you want to do it the manual way, the now-recommended method is to install using the get-pip.py script from pip's installation instructions.

    Install pip

    To install pip, securely download get-pip.py

    Then run the following (which may require administrator access):

    python get-pip.py 
    

    If setuptools is not already installed, get-pip.py will install setuptools for you.

    0 讨论(0)
  • 2020-11-22 02:06

    Assuming you are in a highly restricted computer env (such as myself) without root access or ability to install packages...

    I had never setup a fresh/standalone/raw/non-root instance of Python+virtualenv before this post. I had do quite a bit of Googling to make this work.

    1. Decide if you are using python (python2) or python3 and set your PATH correctly. (I am strictly a python3 user.) All commands below can substitute python3 for python if you are python2 user.
    2. wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-x.y.z.tar.gz
    3. tar -xzvf virtualenv-x.y.z.tar.gz
    4. python3 virtualenv-x.y.z/virtualenv.py --python $(which python3) /path/to/new/virtualenv
    5. source /path/to/new/virtualenv/bin/activate
      • Assumes you are using a Bourne-compatible shell, e.g., bash
      • Brilliantly, this virtualenv package includes a standalone version of pip and setuptools that are auto-magically installed into each new virtualenv. This solves the chicken and egg problem.
      • You may want to create an alias (or update your ~/.bashrc, etc.) for this final command to activate the python virtualenv during each login. It can be a pain to remember all these paths and commands.
    6. Check your version of python now: which python3 should give: /path/to/new/virtualenv/bin/python3
    7. Check pip is also available in the virtualenv via which pip... should give: /path/to/new/virtualenv/bin/pip

    Then... pip, pip, pip!

    Final tip to newbie Pythoneers: You don't think you need virtualenv when you start, but you will be happy to have it later. Helps with "what if" installation / upgrade scenarios for open source / shared packages.

    Ref: https://virtualenv.pypa.io/en/latest/installation.html

    0 讨论(0)
提交回复
热议问题