Dealing with multiple Python versions and PIP?

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

    pip is also a python package. So the easiest way to install modules to a specific python version would be below

     python2.7 /usr/bin/pip install foo
    

    or

    python2.7 -m pip install foo
    
    0 讨论(0)
  • 2020-11-21 07:23

    This is probably the completely wrong thing to do (I'm a python noob), but I just went in and edited the pip file

    #!/usr/bin/env python3 <-- I changed this line.
    
    # -*- coding: utf-8 -*-
    import re
    import sys
    
    from pip._internal import main
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
        sys.exit(main())
    
    0 讨论(0)
  • 2020-11-21 07:26

    I had python 2.6 installed by default (Amazon EC2 AMI), but needed python2.7 plus some external packages for my application. Assuming you already installed python2.7 alongside with default python (2.6 in my case). Here is how to install pip and packages for non-default python2.7

    Install pip for your python version:

    curl -O https://bootstrap.pypa.io/get-pip.py
    python27 get-pip.py
    

    Use specific pip version to install packages:

    pip2.7 install mysql-connector-python --allow-external mysql-connector-python
    
    0 讨论(0)
  • 2020-11-21 07:27

    for Blender:

    /usr/bin $ python3.7 -m pip install irc
    
    0 讨论(0)
  • 2020-11-21 07:28

    For windows specifically: \path\to\python.exe -m pip install PackageName works.

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

    Another possible way could be using conda and pip. Some time you probably want to use just one of those, but if you really need to set up a particular version of python I combine both.

    1. I create a starting conda enviroment with the python I want. As in here https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html. Alternatively you could set up the whole enviroment just using conda.

      conda create -n myenv python=3.6.4

    2. Then activate your enviroment with the python you like. This command could change depending on the OS.

      source activae myenv

    3. Now you have your python active then you could continue using conda but if you need/want to use pip:

      python -m pip -r requirements.txt

    Here you have a possible way.

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