How to install python3 version of package via pip on Ubuntu?

前端 未结 17 1767
粉色の甜心
粉色の甜心 2020-11-22 11:03

I have both python2.7 and python3.2 installed in Ubuntu 12.04.
The symbolic link python links to python2.7

相关标签:
17条回答
  • 2020-11-22 11:22

    Short Answer

    sudo apt-get install python3-pip
    sudo pip3 install MODULE_NAME
    

    Source: Shashank Bharadwaj's comment

    Long Answer

    The short answer applies only on newer systems. On some versions of Ubuntu the command is pip-3.2:

    sudo pip-3.2 install MODULE_NAME
    

    If it doesn't work, this method should work for any Linux distro and supported version:

    sudo apt-get install curl
    curl https://bootstrap.pypa.io/get-pip.py | sudo python3
    sudo pip3 install MODULE_NAME
    

    If you don't have curl, use wget. If you don't have sudo, switch to root. If pip3 symlink does not exists, check for something like pip-3.X

    Much python packages require also the dev package, so install it too:

    sudo apt-get install python3-dev
    

    Sources:
    python installing packages with pip
    Pip latest install

    Check also Tobu's answer if you want an even more upgraded version of Python.

    I want to add that using a virtual environment is usually the preferred way to develop a python application, so @felixyan answer is probably the best in an ideal world. But if you really want to install that package globally, or if need to test / use it frequently without activating a virtual environment, I suppose installing it as a global package is the way to go.

    0 讨论(0)
  • 2020-11-22 11:24

    If your system has python2 as default, use below command to install packages to python3

    $ python3 -m pip install <package-name>

    0 讨论(0)
  • 2020-11-22 11:25

    Well, on ubuntu 13.10/14.04, things are a little different.

    Install

    $ sudo apt-get install python3-pip
    

    Install packages

    $ sudo pip3 install packagename
    

    NOT pip-3.3 install

    0 讨论(0)
  • 2020-11-22 11:26

    Another way to install python3 is using wget. Below are the steps for installation.

    wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
    tar xJf ./Python-3.3.5.tar.xz
    cd ./Python-3.3.5
    ./configure --prefix=/opt/python3.3
    make && sudo make install
    

    Also,one can create an alias for the same using

    echo 'alias py="/opt/python3.3/bin/python3.3"' >> ~/.bashrc
    

    Now open a new terminal and type py and press Enter.

    0 讨论(0)
  • 2020-11-22 11:28

    The easiest way to install latest pip2/pip3 and corresponding packages:

    curl https://bootstrap.pypa.io/get-pip.py | python2
    pip2 install package-name    
    
    curl https://bootstrap.pypa.io/get-pip.py | python3
    pip3 install package-name
    

    Note: please run these commands as root

    0 讨论(0)
  • 2020-11-22 11:31

    Easy enough:

    sudo aptitude install python3-pip
    pip-3.2 install --user pkg
    

    If you want Python 3.3, which isn't the default as of Ubuntu 12.10:

    sudo aptitude install python3-pip python3.3
    python3.3 -m pip.runner install --user pkg
    
    0 讨论(0)
提交回复
热议问题