Dealing with multiple Python versions and PIP?

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

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

提交回复
热议问题