Dealing with multiple Python versions and PIP?

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

    Other answers show how to use pip with both 2.X and 3.X Python, but does not show how to handle the case of multiple Python distributions (eg. original Python and Anaconda Python).

    I have a total of 3 Python versions: original Python 2.7 and Python 3.5 and Anaconda Python 3.5.

    Here is how I install a package into:

    1. Original Python 3.5:

      /usr/bin/python3 -m pip install python-daemon
      
    2. Original Python 2.7:

      /usr/bin/python -m pip install python-daemon
      
    3. Anaconda Python 3.5:

      python3 -m pip install python-daemon
      

      or

      pip3 install python-daemon
      

      Simpler, as Anaconda overrides original Python binaries in user environment.

      Of course, installing in anaconda should be done with conda command, this is just an example.


    Also, make sure that pip is installed for that specific python.You might need to manually install pip. This works in Ubuntu 16.04:

    sudo apt-get install python-pip 
    

    or

    sudo apt-get install python3-pip
    

提交回复
热议问题