Dealing with multiple Python versions and PIP?

后端 未结 23 2817
走了就别回头了
走了就别回头了 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:35

    Most of the answers here address the issue but I want to add something what was continually confusing me with regard to creating an alternate installation of python in the /usr/local on CentOS 7. When I installed there, it appeared like pip was working since I could use pip2.7 install and it would install modules. However, what I couldn't figure out was why my newly installed version of python wasn't seeing what I was installing.

    It turns out in CentOS 7 that there is already a python2.7 and a pip2.7 in the /usr/bin folder. To install pip for your new python distribution, you need to specifically tell sudo to go to /usr/local/bin

    sudo /usr/local/bin/python2.7 -m ensurepip
    

    This should get pip2.7 installed in your /usr/local/bin folder along with your version of python. The trick is that when you want to install modules, you either need to modify the sudo $PATH variable to include /usr/local/bin or you need to execute

    sudo /usr/local/bin/pip2.7 install <module>
    

    if you want to install a new module. It took me forever to remember that sudo wasn't immediately seeing /usr/local/bin.

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

    Installation of multiple versions of Python and respective Packages.

    Python version on the same windows machine : 2.7 , 3.4 and 3.6

    Installation of all 3 versions of Python :

    • Installed the Python 2.7 , 3.4 and 3.6 with the below paths

    PATH for all 3 versions of Python :

    • Made sure the PATH variable ( in System Variables ) has below paths included - C:\Python27\;C:\Python27\Scripts;C:\Python34\;C:\Python34\Scripts;C:\Python36\;C:\Python36\Scripts\;

    Renaming the executables for versions :

    • Changed the python executable name in C:\Python36 and C:\Python34 to python36 and python34 respectively.

    Checked for the command prompt with all versions :

    Installing the packages separately for each version

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

    for example, if you set other versions (e.g. 3.5) as default and want to install pip for python 2.7:

    1. download pip at https://pypi.python.org/pypi/pip (tar)
    2. unzip tar file
    3. cd to the file’s directory
    4. sudo python2.7 setup.py install
    0 讨论(0)
  • 2020-11-21 07:39

    You can go to for example C:\Python2.7\Scripts and then run cmd from that path. After that you can run pip2.7 install yourpackage...

    That will install package for that version of Python.

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

    If you have both python3.6 and python3.7 installed and want to use pip with python3.7 by default, here's what you should do:

    First make sure you have pip installed for python3.7

    python3.7 -m pip install -U pip
    

    Now pip3.7 must be available, so we edit .bashrc

    nano ~/.bashrc
    

    adding the following line to it

    alias pip=pip3.7
    

    In order for the changes to take effect type in the shell:

    source ~/.bashrc
    

    Now if you type:

    pip --version
    

    you should get:

    pip 20.1.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

    which means, if you use, for example:

    pip install <package>
    

    it would install the <package> for python3.7

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