Dealing with multiple Python versions and PIP?
Asked Answered
S

30

734

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 site 2.5 installation or my site 2.6 installation.

For example, with easy_install, I use easy_install-2.{5,6}.

And, yes — I know about virtualenv, and no — it's not a solution to this particular problem.

Sash answered 11/5, 2010 at 16:32 Comment(3)
@YiboYang does it work with things like pip34 and pip35?Prevaricate
@Prevaricate It should, provided pip3.x actually manages the python version that you want to install packages to (perhaps run pip3.x -V to see). Or use @Hugo's solution to have better control over lots of python versions.Meneau
Possible duplicate of stackoverflow.com/questions/10919569/…Albany
M
957

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:

Mendelsohn answered 5/2, 2011 at 23:24 Comment(19)
Doesn't work. Although the latest version of pip installed a pip-2.6 script, it didn't bother to install a pip-2.5 script.Sirree
You need to update your python2.5 pip version... It only creates pip-{PYVERSION} under the python you are using pip.Mendelsohn
This is incorrect. I'm running pip 1.2.1 with Python2.7 on Ubuntu, and there are no alternative pip versions.Econometrics
@Cerin, you may have installed only one version of pip, and then you have only pip and pip-2.7, and that's correct. I have pip installed in my system-wide Python 2.4, and created right now a fresh virtualenv with pip 1.2.1 and it works perfectly: I have a pip, pip-2.7 and pip-2.4. Take a look at my output: gist.github.com/3828343Mendelsohn
@rodling: probably you didn't installed pip via pip/easy_install or get-pip.py or you don't have python2.7. if you have python2.7, try: pip install --upgrade pip and you should have pip and pip-2.7Mendelsohn
FYI - I tried the steps above and found PIP was now using pip2.7 instead of pip-2.7 in CentOSIndianapolis
@Andres: it is not only in CentOS, it was changed in pip 1.5. This pull request introduced this change: github.com/pypa/pip/pull/1053. I am going to update the answer. Thanks!Mendelsohn
@HugoTavares how can I change the default version that runs when only executed 'pip'??Pes
@J.C.Rocamonde: the program pip gets picked based on the environment variable $PATH. If you want to change what is the "default" pip program, reorder the $PATH environment variable. Search for something like "path environment variable linux" for more details on $PATH.Mendelsohn
This still leaves a problem: pip doesn't make versioned scripts executables. So if I install the same package for two versions of python, they will overwrite each other's scripts.Sullen
does simple pip default to the latest version?Delindadelineate
I got a "locale.Error: unsupported locale setting" using this method. Fixed it by using "export LC_ALL=C" before the "python -m pip install ..." command.Walther
what exactly does the -m flag stand for / do?Rudolfrudolfo
How does one distinguish between 32 and 64 bit python?Phlegm
I leave the dash - out. python3.6 instead of python-3.6.Book
If pip wasn't installed with python, then pythonx.y -m pip install fish will generate the error /usr/bin/pythonx.y: No module named pip. This can be resolved by installing pip, as per these instructions for Ubuntu.Dinkins
Why these both mixes up every time?Vengeance
this doesnt work with python 3 it seems?Atone
none of these, except specifying the path to the python executable, worked for me.Atone
T
182

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
Troublesome answered 16/5, 2016 at 10:40 Comment(7)
having both 2.7 and 3.5 installed on windows, this worked right awayMyramyrah
Is there no way to have python2, python3, pip2 and pip3 on Windows?Dracaena
this worked for me on windows. had 3 installed and then installed 2Sibilate
Thank you, this worked for me! Can't believe how difficult it was. (None of these or variations python-3.7 -m pip install or python-3.7 -m pip install or python3.7 -m pip install worked for me...)Monzonite
py -3.6 -m pip install packagename does not work. I get "Unknown option: -3" Nor do the options jeppoo1 tried.Uneven
How does py know where each version is located? Is it something that I can configure myself?Bridgework
none of these, except specifying the path, worked for me.Atone
W
79

/path/to/python2.{5,6} /path/to/pip install PackageName doesn't work?

For this to work on any python version that doesn't have pip already installed you need to download pip and do python*version* setup.py install. For example python3.3 setup.py install. This resolves the import error in the comments. (As suggested by @hbdgaf)

Whiteside answered 11/5, 2010 at 16:32 Comment(6)
For this to work on say python 3 you need to download pip and do "python3 setup.py install". Personally I find this solution to be not very nice. For a start I didn't even know the pip command wasn't a binary. This isn't a criticism of @bwinton, I'm just surprised there isn't a better way to do this.Twice
"ImportError: No module named pkg_resources"Econometrics
Same as @Econometrics "ImportError: No module named pkg_resources"Lesbianism
I'm baffled that the problem with the importerror got more upticks than the solution to the same one comment above it.Papism
Also, /path/to/pip is this: python2.{5,6}/Scripts/pip2.{5,6}Elene
To call a module of python you should use python2.7 -m pip install PackageNameDecalescence
B
58

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
Besnard answered 24/8, 2014 at 17:12 Comment(7)
great worked for me for python 3.4 with following: python3 get-pip.py and later using pip command with pip34 install exampleConstellate
This worked when I used 'python2.7 get-pip.py' instead of 'python27 get-pip.py'Bathurst
Man that felt sketchy but it worked for me installing pip2.6 on Centos 5.Husch
Got Could not find a version that satisfies the requirement pip (from versions: ) No matching distribution found for pip when I tried python2.6 get-pip.pyLon
How to do python2.7 get-pip.py without sudo?Vine
Worked for me on Win 7 64 bits on which I have installed Python 2.7.x 32 bits and 3.5.x 64 bitsPagepageant
This is not a solution if the host does not have internet connectivity. What does that script do?Nitroglycerin
C
31

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

Criminology answered 18/5, 2016 at 19:42 Comment(1)
Just for anyone else figuring out how to install packages in python3 using pip on mac, this command is how you install packages. I spent hours searching and I've finally found it!Delusion
C
29

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
Counteract answered 9/10, 2016 at 18:10 Comment(4)
The advice regarding Anaconda here is not accurate... it doesn't "override" anything. The fact that it is picking up the Anaconda version as default on your system is simply a side-effect of your specific configuration, how you installed each interpreter, and your environment's path ordering.... those will vary for others.Labradorite
@CoreyGoldberg I agree, it was the default on my installation of Ubuntu 16.04Counteract
You sir, are the man. Of all the totally useless explanations surrounding this issue, this is the only one that has made sense to me. Time to alias these commands and get on with my life! THANK YOU.Jaenicke
This is pretty confusing on ubuntu the python3 pip installs as pip command and python 3.6 as python3. python2.7 installs as python command and pip for it installs as pip2.Coraciiform
M
17

From here: https://docs.python.org/3/installing/

Here is how to install packages for various versions that are installed at the same time linux, mac, posix:

python2   -m pip install SomePackage  # default Python 2
python2.7 -m pip install SomePackage  # specifically Python 2.7
python3   -m pip install SomePackage  # default Python 3
python3.4 -m pip install SomePackage  # specifically Python 3.4
python3.5 -m pip install SomePackage  # specifically Python 3.5
python3.6 -m pip install SomePackage  # specifically Python 3.6

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

py -2   -m pip install SomePackage  # default Python 2
py -2.7 -m pip install SomePackage  # specifically Python 2.7
py -3   -m pip install SomePackage  # default Python 3
py -3.4 -m pip install SomePackage  # specifically Python 3.4
Morava answered 1/1, 2017 at 0:43 Comment(1)
Also consider checking out: pipenvMorava
O
14

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>
Obala answered 4/3, 2016 at 7:0 Comment(0)
C
13

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
Commonage answered 2/4, 2017 at 6:33 Comment(0)
T
10

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
>>> 
Tyrelltyrian answered 8/4, 2013 at 12:5 Comment(0)
A
10

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
Aryn answered 12/4, 2018 at 20:18 Comment(0)
B
6

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

enter image description here

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.

enter image description here

Checked for the command prompt with all versions :

enter image description here

Installing the packages separately for each version

enter image description here

Benedetto answered 14/3, 2019 at 14:37 Comment(0)
C
5

If you have multiple versions as well as multiple architectures (32 bit, 64 bit) you will need to add a -32 or -64 at the end of your version.

For windows, go to cmd and type py --list and it will produce the versions you have installed. The list will look like the following:

Installed Pythons found by py Launcher for Windows
 -3.7-64 *
 -3.7-32
 -3.6-32

The full command as an example will be:

py -3.6-32 -m pip install (package)

If you want to get more indepth, to install a specific version of a package on a specific version of python, use ==(version) after the package. As an example,

py -3.6-32 -m pip install opencv-python==4.1.0.25
Closefisted answered 18/9, 2019 at 15:55 Comment(0)
H
4

Here is my take on the problem. Works for Python3. The main features are:

  • Each Python version is compiled from source
  • All versions are installed locally
  • Does not mangle your system's default Python installation in any way
  • Each Python version is isolated with virtualenv

Prerequisites: If you are using some bare-bones thin client with no extra turf installed, you should run this first (in ubuntu 18.04 at least, extra packages added for convenience):

sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-add-repository universe
sudo apt-get update
sudo apt-get install -y build-essential cmake

sudo apt-get install -y zlib1g zlib1g-dev libsqlite3-dev \
openssl libssl-dev libffi-dev unzip pciutils net-tools \
libblas-dev gfortran libblas3 

The steps are as follows:

  1. If you have several extra python versions installed in some other way, get rid of them, e.g., remove $HOME/.local/lib/python3.x, etc. (also the globally installed ones). Don't touch your system's default python3 version though.

  2. Download source for different python versions under the following directory structure:

     $HOME/
         python_versions/ : download Python-*.tgz packages here and "tar xvf" them.  You'll get directories like this:
           Python-3.4.8/
           Python-3.6.5/
           Python-3.x.y/
           ...
    
  3. At each "Python-3.x.y/" directory, do the following (do NOT use "sudo" in any of the steps!):

     mkdir root
     ./configure --prefix=$PWD/root 
     make -j 2
     make install
     virtualenv --no-site-packages -p root/bin/python3.x env
    
  4. At "python_versions/" create files like this:

     env_python3x.bash:
    
     #!/bin/bash
     echo "type deactivate to exit"
     source $HOME/python_versions/Python-3.x.y/env/bin/activate
    
  5. Now, anytime you wish to opt for python3.x, do

     source $HOME/python_versions/env_python3x.bash
    

to enter the virtualenv

  1. While in the virtualenv, install your favorite python packages with

     pip install --upgrade package_name
    
  2. To exit the virtualenv and python version just type "deactivate"

UPDATE

It seems that --no-site-packages is deprecated. There's an easy fix for this: Once you have activated the virtualenv, just point the HOME env variable to somewhere else than your actual home directory, i.e.:

export HOME=some/where/else

A nice way to do this in general is:

  • Create virtualenv
  • Activate virtualenv
  • If you want to "recycle" existing libraries to your virtualenv, softlink them from your existing install, i.e. ln -s $HOME/.local/lib/python3.6/site-packages/numpy $PWD/venv/lib/python3.6/site-packages/
  • Do export PYTHONPATH=, export HOME=/some/other/dir

Now you should have custom-isolated virtualenv.

UPDATE 2 / SUDO

Wan't to force sudo to use your virtualenv?

Defaults        secure_path="/home/USENAME/Python-3.x.y/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
Defaults        env_keep += "VIRTUAL_ENV"
Defaults        env_keep += "PYTHONPATH"

Now try "sudo python3 --version" and magic should happen

UPDATE 3 / DOCKER

Enable virtualenv inside your docker (of course, you have built it in your docker image):

ENV VIRTUAL_ENV=/home/USER/Python-3.x.y/env
ENV PYTHONPATH=
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
Hexachlorophene answered 13/5, 2018 at 18:21 Comment(0)
R
3

You can use one of the following commands:

pip2 install SomePackage
pip3 install SomePackage

python2 -m pip install SomePackage  
python3 -m pip install SomePackage 

And of course, make sure that you have the correct version of pip installed

sudo apt-get install python-pip
sudo apt-get install python3-pip

I haven't used these commands myself but, some answers above suggests using them to specify exactly the version of python you want to use

pip-2.7 install SomePackage
python-3.6 -m pip install SomePackage
Raillery answered 14/1, 2021 at 18:47 Comment(0)
H
3

For python 3 and Windows OS, I always use this syntax to install packages on different version:

First I always use Git Bash Command Prompt.

Here an example installing urllib package.

Default Python version:(The normal pip command)

pip install urllib3

For the other versions

py -3.8 -m pip install urllib3

py => for python

-3.8 => for the version (I'm using the 3.8.7 version) but if you're using the 3.7.7 version it will be "-3.7"

-m : just because or for modify

pip install urllib3 : the normal pip command

Heterosexuality answered 18/2, 2021 at 23:17 Comment(0)
B
2

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.

Beckwith answered 18/12, 2017 at 1:51 Comment(0)
C
2

Starting from 22.3, you can use --python option to allow pip to manage Python environments other than the one pip is installed in.

python -m pip --python <PATH_TO_PYTHON_INTERPRETER_YOU_WANT_TO_MANAGE> install package_name

Quoting from the documentation:

Occasionally, you may want to use pip to manage a Python installation other than the one pip is installed into. In this case, you can use the --python option to specify the interpreter you want to manage. This option can take one of two values:

  1. The path to a Python executable.
  2. The path to a virtual environment.

In both cases, pip will run exactly as if it had been invoked from that Python environment.

One example of where this might be useful is to manage a virtual environment that does not have pip installed.

$ python -m venv .venv --without-pip
$ python -m pip --python .venv install SomePackage
[...]
Successfully installed SomePackage

You could also use --python .venv/bin/python (or on Windows, --python .venv\Scripts\python.exe) if you wanted to be explicit, but the virtual environment name is shorter and works exactly the same.

Cyano answered 3/1 at 8:4 Comment(0)
P
0

Context: Archlinux

Action:
Install python2-pip:
sudo pacman -S python2-pip

You now have pip2.7:
sudo pip2.7 install boto

Test (in my case I needed 'boto'):
Run the following commands:

python2
import boto

Success: No error.

Exit: Ctrl+D

Pirandello answered 28/10, 2016 at 13:44 Comment(0)
T
0

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
Tetrad answered 6/1, 2017 at 9:2 Comment(0)
F
0

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

Fiddlededee answered 27/7, 2020 at 20:41 Comment(4)
Forget the pip scripts, they are unreliable. Just use path/to/pythonX.Y -m pip, it's safer.Autogiro
Never had problems with it. So I don't see any reason to forget it yet. And I don't think that makes my answer "not useful"Fiddlededee
/usr/bin/python3.8: No module named pipPorcine
@EvanZamir you probably haven't installed pip for python3.8. Please see this question on stackoverflow https://mcmap.net/q/20831/-pip-for-python-3-8Fiddlededee
A
0

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.

Adolf answered 22/8, 2020 at 9:22 Comment(0)
S
0

To use multiple versions of pip, just type

pip{version} and run command

Example: for python 3.10

pip3.10

pip3.10 list

pip3.10

for Python 3.7

pip3.7

pip3.7 list

Strict answered 28/7, 2022 at 18:4 Comment(0)
I
0

Updating PIP and installing Packages while using specific location of pip:

I was getting an intermittent error "Access Denied" when using the simple comand line pip install <library> on some lab machines that were using pip from a c:\users\... folder instead of the c:\Program Files\Python folder for all users. Thanks to MultiplyByZer0 answer above I was able to implement a solution that specified the path to python and then run pip.

Here is the powershell script I use to force pip update and then install python libraries:

$fullPath = "C:\Program Files\Python38"
$thisApp = "python.exe"
$arguments = "-m pip install --upgrade pip"
$appPath = join-path $fullPath $thisApp
Start-Process $appPath $arguments  -Verb RunAs -Wait
$packages = @(  "pylint"
                "pillow"
                "pygame"
                "matplotlib"
                "pandas"
                "godirect")
foreach ($package in $packages)
   {
       Write-Host "Installing python Package" $package -ForegroundColor Yellow
       $arguments = "-m pip install $package"
       Start-Process $appPath $arguments  -Verb RunAs -Wait
   }
Intravenous answered 16/3, 2023 at 20:32 Comment(0)
K
0

Updated according to latest Ubuntu-LTS 22.04 and for python 3, however similar instructions can be followed for python 2 with appropriate version changes.

You can consider pyenv python environment manager which lets you configure different versions of python parallely without needing to create a separate virtualenv or requiring separate pip installed.

The installation instructions can be found here and it is pretty easy to configure pyenv. https://github.com/pyenv/pyenv#readme

This does however require you to install prerequisite libraries which can be installed as follows:

Redhat based systems

sudo yum install git gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel make curl llvm

Ubuntu/Debian based linux systems

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev 
 libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git

After installing prerequisites follow the instructions in the README.md Once installation is finished, to check python versions present in your system run the following in your terminal

pyenv versions

Note if you have installed python versions before setting up pyenv it may not detect the installed versions and you might have to remove them including dependencies. Take care to not remove important lib files while doing so.

To install a new version of python

pyenv install <version_number> # like 3.9 for installing python3.9

Once installed to set the python version as default run the following.

pyenv global <version_number> # to set it globally
pyenv local <version_number> # to set it in the local directory

You can switch between installed Python versions at any time using the pyenv global, pyenv local, or pyenv shell commands with the desired version number.

Note that this arrangement is different from a virtual environment as it allows you to manage multiple versions of python at a system-wide level while using other system level libraries and packages. However pyenv does have plugins to enable virtualenv support which can be installed from instructions listed here https://github.com/pyenv/pyenv-virtualenv#readme

Pyenv can be removed by simply deleting the pyenv folder and reverting any changes made to .bashrc, .bash_profile and/or similar files.

Hope this helps.

Kraska answered 24/7, 2023 at 17:51 Comment(0)
I
-1

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.

Injustice answered 16/3, 2018 at 9:32 Comment(0)
H
-1

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())
Heptateuch answered 14/1, 2019 at 21:3 Comment(1)
Please don't do this. The purpose of how pip is set up is so that you can install to any given version of Python by choosing that version of Python yourself to run pip. Having pip rely on system machinery to choose a Python version, defeats that scheme.Principle
V
-2

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

Vaudois answered 26/6, 2019 at 19:17 Comment(1)
No luck here with that.Uneven
P
-2

for Blender:

/usr/bin $ python3.7 -m pip install irc
Puklich answered 14/11, 2019 at 8:22 Comment(0)
A
-2

Some useful information for debugging this is the pip debug command. It shows the location of the python interpreter that it is attached to in the 1st line (after the warning).

$ pip debug
WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without notice.
pip version: pip 21.2.4 from /data/akshay/anaconda3/lib/python3.9/site-packages/pip (python 3.9)
sys.version: 3.9.12 (main, Apr  5 2022, 06:56:58)
sys.executable: /data/akshay/anaconda3/bin/python 
Astrogate answered 18/8, 2022 at 14:18 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewLunation

© 2022 - 2024 — McMap. All rights reserved.