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

前端 未结 17 2058
粉色の甜心
粉色の甜心 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.

提交回复
热议问题