How do I install packages with pip when there are multiple Python versions?
I have different versions of python installed, python 2.7 being the default and 3.2 the second. Now I want to install pyramid to the 3.2 installation. How can I do this?
Just using pip to install pyramid does not work, so how can I change the version it is downloading to?
5 Answers
You have two options, but either way, you need to get easy_install-3.2. Since it doesn't seem to be packaged, you have to install it yourself. Fortunately that's easy. And you should also get python3-pkg-resources, which is packaged:
sudo apt-get install python3-pkg-resources
wget
sudo python3 distribute_setup.pyNow you can just use easy_install-3.2 to install Pyramid, or go ahead and install pip in Python3.
OPTION 1:
sudo easy_install-3.2 pyramidOPTION 2:
sudo easy_install-3.2 pip
sudo pip-3.2 install pyramid 1 Alternatively, if you want to install specific version of the package with the specific version of python, this is the way
sudo python2.7 -m pip install pyudev=0.16If the "=" doesnt work, use "=="
sudo python2.7 -m pip install pyudev=0.16Ouput: Invalid requirement: 'pyudev=0.16' = is not a valid operator. Did you mean == ?
sudo python2.7 -m pip install pyudev==0.16works fine
Each python binary should have its own pip executable.
You get one automatically if you use virtualenv. Then you could just run pip install pyramid in an activated virtualenv e.g.:
$ vex venv pip install pyramidIf you want to use pip to install for a system python3 then you could install pip for it:
$ sudo apt-get install python3-pipIt installs pip3 program. Then:
$ pip3 install --user pyramidinstalls pyramid in ~/.local directory tree.
If you need to test a Python package on several python versions; you could use tox.
In the case where you have installed a separate user-only version of Python by downloading and extracting the tar.gz from the Python.org Downloads page and done a:-
tar -xzf Python-x.x.x.tar.gz
cd Python-x.x.x/
./configure
makeYou can use get-pip to install and run pip for this Python install only.
Download it with curl as per the git-pip instructions. Then, within your Python-x.x.x/ directory, run:
./python -m get-pip.py --user
./python -m pip install pyramid --user You can add this to your .bashrc file:
pip3.8() { python3.8 -m pip "$@"
}After creating a new terminal session simply install packages with:
pip3.8 instal xyz