Install a module using pip for specific python version

后端 未结 14 786
迷失自我
迷失自我 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:47

    As with any other python script, you may specify the python installation you'd like to run it with. You may put this in your shell profile to save the alias. The $1 refers to the first argument you pass to the script.

    # PYTHON3 PIP INSTALL V2
    alias pip_install3="python3 -m $(which pip) install $1"
    
    0 讨论(0)
  • 2020-11-22 17:51

    You can use this syntax

    python_version -m pip install your_package
    

    For example. If you're running python3.5, you named it as "python3", and want to install numpy package

    python3 -m pip install numpy
    
    0 讨论(0)
  • 2020-11-22 17:52

    Alternatively, if you want to install specific version of the package with the specific version of python, this is the way

    sudo python2.7 -m pip install pyudev=0.16
    

    if the "=" doesnt work, use ==

    x@ubuntuserv:~$ sudo python2.7 -m pip install pyudev=0.16

    Invalid requirement: 'pyudev=0.16' = is not a valid operator. Did you mean == ?

    x@ubuntuserv:~$ sudo python2.7 -m pip install pyudev==0.16

    works fine

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

    Python 2

    sudo pip2 install johnbonjovi  
    

    Python 3

    sudo pip3 install johnbonjovi
    
    0 讨论(0)
  • 2020-11-22 17:57

    Have tried this on a Windows machine and it works

    If you wanna install opencv for python version 3.7, heres how you do it!

    py -3.7 -m pip install opencv-python
    
    0 讨论(0)
  • 2020-11-22 18:00

    I had Python 2.7 installed via chocolatey on Windows and found pip2.7.exe in C:\tools\python2\Scripts.

    Using this executable instead of the pip command installed the correct module for me (requests for Python 2.7).

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