Dealing with multiple Python versions and PIP?

后端 未结 23 2760
走了就别回头了
走了就别回头了 2020-11-21 06:58

Is there any way to make pip play well with multiple versions of Python? For example, I want to use pip to explicitly install things to either my s

相关标签:
23条回答
  • 2020-11-21 07:31

    The current recommendation is to use python -m pip, where python is the version of Python you would like to use. This is the recommendation because it works across all versions of Python, and in all forms of virtualenv. For example:

    # The system default python:
    $ python -m pip install fish
    
    # A virtualenv's python:
    $ .env/bin/python -m pip install fish
    
    # A specific version of python:
    $ python-3.6 -m pip install fish
    

    Previous answer, left for posterity:

    Since version 0.8, Pip supports pip-{version}. You can use it the same as easy_install-{version}:

    $ pip-2.5 install myfoopackage
    $ pip-2.6 install otherpackage
    $ pip-2.7 install mybarpackage
    

    EDIT: pip changed its schema to use pipVERSION instead of pip-VERSION in version 1.5. You should use the following if you have pip >= 1.5:

    $ pip2.6 install otherpackage
    $ pip2.7 install mybarpackage
    

    Check https://github.com/pypa/pip/pull/1053 for more details


    References:

    • https://github.com/pypa/pip/issues/200
    • http://www.pip-installer.org/docs/pip/en/0.8.3/news.html#id4
    0 讨论(0)
  • 2020-11-21 07:32

    It worked for me in windows this way:

    1. I changed the name of python files python.py and pythonw.exe to python3.py pythonw3.py

    2. Then I just ran this command in the prompt:

      python3 -m pip install package

    0 讨论(0)
  • 2020-11-21 07:32

    On Linux, Mac OS X and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip:

    python2.7 -m pip install SomePackage
    python3.4 -m pip install SomePackage
    

    (appropriately versioned pip commands may also be available)

    On Windows, use the py Python launcher in combination with the -m switch:

    py -2.7 -m pip install SomePackage  # specifically Python 2.7
    py -3.4 -m pip install SomePackage  # specifically Python 3.4
    

    if you get an error for py -3.4 then try:

    pip install SomePackage
    
    0 讨论(0)
  • 2020-11-21 07:33

    On Windows, you can execute the pip module using a given Python version through the Python launcher, py.exe, if you chose to install it during Python 3 setup.

    py -3 -m pip install packagename
    py -2 -m pip install packagename
    

    You can be even more specific and request an exact sub-version of Python:

    py -3.6 -m pip install packagename
    

    To get a list of all installed Python versions available through the launcher, run:

    py --list
    

    Alternatively, you can launch the desired Python executable directly:

    C:/path/to/specific/python.exe -m pip install packagename
    
    0 讨论(0)
  • 2020-11-21 07:33

    So apparently there are multiple versions of easy_install and pip. It seems to be a big mess. Anyway, this is what I did to install Django for Python 2.7 on Ubuntu 12.10:

    $ sudo easy_install-2.7 pip
    Searching for pip
    Best match: pip 1.1
    Adding pip 1.1 to easy-install.pth file
    Installing pip-2.7 script to /usr/local/bin
    
    Using /usr/lib/python2.7/dist-packages
    Processing dependencies for pip
    Finished processing dependencies for pip
    
    $ sudo pip-2.7 install django
    Downloading/unpacking django
      Downloading Django-1.5.1.tar.gz (8.0Mb): 8.0Mb downloaded
      Running setup.py egg_info for package django
    
        warning: no previously-included files matching '__pycache__' found under directory '*'
        warning: no previously-included files matching '*.py[co]' found under directory '*'
    Installing collected packages: django
      Running setup.py install for django
        changing mode of build/scripts-2.7/django-admin.py from 644 to 755
    
        warning: no previously-included files matching '__pycache__' found under directory '*'
        warning: no previously-included files matching '*.py[co]' found under directory '*'
        changing mode of /usr/local/bin/django-admin.py to 755
    Successfully installed django
    Cleaning up...
    
    $ python
    Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import django
    >>> 
    
    0 讨论(0)
  • 2020-11-21 07:35

    I ran into this issue myself recently and found that I wasn't getting the right pip for Python 3, on my Linux system that also has Python 2.

    First you must ensure that you have installed pip for your python version:

    For Python 2:

    sudo apt-get install python-pip
    

    For Python 3:

    sudo apt-get install python3-pip
    

    Then to install packages for one version of Python or the other, simply use the following for Python 2:

    pip install <package>
    

    or for Python 3:

    pip3 install <package>
    
    0 讨论(0)
提交回复
热议问题