Install a module using pip for specific python version

后端 未结 14 784
迷失自我
迷失自我 2020-11-22 17:14

On Ubuntu 10.04 by default Python 2.6 is installed, then I have installed Python 2.7. How can I use pip install to install packages for Python 2.7.

For

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

    Alternatively, since pip itself is written in python, you can just call it with the python version you want to install the package for:

    python2.7 -m pip install foo
    
    0 讨论(0)
  • 2020-11-22 17:41

    You can execute pip module for a specific python version using the corresponding python:

    Python 2.6:

    python2.6 -m pip install beautifulsoup4
    

    Python 2.7

    python2.7 -m pip install beautifulsoup4
    
    0 讨论(0)
  • 2020-11-22 17:42

    Use a version of pip installed against the Python instance you want to install new packages to.

    In many distributions, there may be separate python2.6-pip and python2.7-pip packages, invoked with binary names such as pip-2.6 and pip-2.7. If pip is not packaged in your distribution for the desired target, you might look for a setuptools or easyinstall package, or use virtualenv (which will always include pip in a generated environment).

    pip's website includes installation instructions, if you can't find anything within your distribution.

    0 讨论(0)
  • 2020-11-22 17:43

    For Python 3

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

    For Python 2

    sudo apt-get install python2-pip
    sudo pip2 install beautifulsoup4
    

    On Debian/Ubuntu, pip is the command to use when installing packages for Python 2, while pip3 is the command to use when installing packages for Python 3.

    0 讨论(0)
  • 2020-11-22 17:45

    If you have both 2.7 and 3.x versions of python installed, then just rename the python exe file of python 3.x version to something like - "python.exe" to "python3.exe". Now you can use pip for both versions individually. If you normally type "pip install " it will consider the 2.7 version by default. If you want to install it on the 3.x version you need to call the command as "python3 -m pip install ".

    0 讨论(0)
  • 2020-11-22 17:45

    I faced a similar problem with another package called Twisted. I wanted to install it for Python 2.7, but it only got installed for Python 2.6 (system's default version).

    Making a simple change worked for me.

    When adding Python 2.7's path to your $PATH variable, append it to the front like this: PATH=/usr/local/bin:$PATH, so that the system uses that version.

    If you face more problems, you can follow this blog post which helped me - https://github.com/h2oai/h2o-2/wiki/installing-python-2.7-on-centos-6.3.-follow-this-sequence-exactly-for-centos-machine-only

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