I would say there is no Debian equivalent to Ubuntu's deadsnakes PPA
Under Debian, using Ubuntu packages or repositories is not recommended. As this post appears in search engines, I propose here an answer that is less dangerous for a Debian system.
Installing Python manually is possible. As an example, you can use the following instructions to install 3.5.2 version
Prerequisites
Install dependencies :
sudo apt-get update && sudo apt-get install libssl-dev openssl
Building Python
You can build Python in a specific folder using the --prefix parameter from configure command:
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar zxf Python-3.5.2.tgz
cd Python-3.5.2/
./configure --prefix=/usr/local
make
sudo make install
Instead of /usr/local, one can use another base directory. As an example:
sudo mkdir /opt/python-3.5.2
./configure --prefix=/opt/python-3.5.2
Selecting python version
Using PATH environment variable can help choosing the right python version to use. But one can also use symlinks:
sudo ln -s /opt/python-3.5.2/bin/python3.5 /usr/local/bin/python3
sudo ln -s /opt/python-3.5.2/bin/pip3.5 /usr/local/bin/pip3
Using -f option will allow you to replace existing symlinks
Note: For python 3.9.16 (possibly any +3.9 version) you also might need to install the library: libffi-dev so the dependencies would be:
sudo apt-get update && sudo apt-get install libssl-dev openssl libffi-dev
Answer from lauhub on Stack ExchangeI would say there is no Debian equivalent to Ubuntu's deadsnakes PPA
Under Debian, using Ubuntu packages or repositories is not recommended. As this post appears in search engines, I propose here an answer that is less dangerous for a Debian system.
Installing Python manually is possible. As an example, you can use the following instructions to install 3.5.2 version
Prerequisites
Install dependencies :
sudo apt-get update && sudo apt-get install libssl-dev openssl
Building Python
You can build Python in a specific folder using the --prefix parameter from configure command:
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar zxf Python-3.5.2.tgz
cd Python-3.5.2/
./configure --prefix=/usr/local
make
sudo make install
Instead of /usr/local, one can use another base directory. As an example:
sudo mkdir /opt/python-3.5.2
./configure --prefix=/opt/python-3.5.2
Selecting python version
Using PATH environment variable can help choosing the right python version to use. But one can also use symlinks:
sudo ln -s /opt/python-3.5.2/bin/python3.5 /usr/local/bin/python3
sudo ln -s /opt/python-3.5.2/bin/pip3.5 /usr/local/bin/pip3
Using -f option will allow you to replace existing symlinks
Note: For python 3.9.16 (possibly any +3.9 version) you also might need to install the library: libffi-dev so the dependencies would be:
sudo apt-get update && sudo apt-get install libssl-dev openssl libffi-dev
Using the PPA
You can use the PPA on Debian. Pick an Ubuntu version that's from slightly before your Debian version, and it should have all the necessary libraries. For wheezy, the oneiric PPA seems ok (but it lacks more recent Python versions). For jessie, the trusty PPA should work.
To add a PPA on Debian,
Download and add the PPA signing key with:
gpg --keyserver keyserver.ubuntu.com --recv-keys F23C5A6CF475977595C89F51BA6932366A755776 gpg --export F23C5A6CF475977595C89F51BA6932366A755776 | sudo tee /usr/share/keyrings/ppa-deadsnakes.gpg > /dev/nullThen create a file
/etc/apt/sources.list.d/ppa-deadsnakes.listcontaining:deb [signed-by=/usr/share/keyrings/ppa-deadsnakes.gpg] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ trusty main deb-src [signed-by=/usr/share/keyrings/ppa-deadsnakes.gpg] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ trusty mainFinally run
apt-get updateand install the desired packages.
If you can't get the PPA working for some reasons (maybe you can't find a version that works with the libraries you have), you can download the source and recompile them for your distribution.
Using a chrooted system
What I usually do to test compatibility with other versions is to run older or newer distributions in a chrooted system. For example, you could install various versions of Ubuntu with the Python versions you're interested in, or you could install trusty in a chroot and install the PPA there. For more information, see my schroot guide.
I'm Debian 12 Bookworm, the default python version is 3.11. My problem is that it does not support some libraries I want to use yet. So how do I install a specific python version? apt search for python 3.9 returns nothing.
Videos
Felix Krull runs a PPA offering basically any version of Python (seriously, there is 2.3.7 build for vivid...) for many Ubuntu releases at https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa.
Do the usual:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.5
It will not overwrite your existing python3.4 which is still symlinked as python3.
Instead, to run python3.5, run the command python3.5 (or python3.X for any other version of python).
DON'T change the symlink! There are apparently many system functions that don't work properly with python3.5.
I tried this and afterwards couldn't open a terminal, software updater,...
cd /usr/bin
sudo rm python3
The upgrade to Wily will adapt the meta-package python3 to point to python3.5. I don't expect any breakage, but at this point the foreign repository is not needed anymore. So to be really safe, you can purge the PPA before doing the upgrade.
This Youtube link helped me to install it.
The steps are:
sudo apt-get install libssl-dev openssl
wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
tar xzvf Python-3.5.0.tgz
cd Python-3.5.0
./configure
make
sudo make install
To check if python is installed type python3.5 else:
sudo ln -fs /opt/Python-3.5.0/Python /usr/bin/python3.5
I am a newbie in debian. I know this is easy to do in ubuntu, but how to do it in debian?
I figured this out on ubuntu 20 in docker (I was running as root). If you are not running as root - this answer won't help you.
# update the package manager
apt-get update
# install git, C/C++ compiler and a text editor (I prefer vim)
apt install -y git software-properties-common curl build-essential vim
# add package source for python distributions
add-apt-repository ppa:deadsnakes/ppa
# install specific version of python with venv and distutils
apt install -y python3.9 python3.9-distutils python3.9-venv
# get pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py
You have to install the version of python that you want, i recommend use dead-sneak, https://www.codegrepper.com/code-examples/whatever/install+python+3.7+from+source+in+ubuntu+linux.
Later set your python version in the venv, something like "virtualenv venv --python=python{python version}" or "python{python version} -m venv venv"
Python has got its own package managing facilities, in parallel to the one sets by the Linux distributions (including Ubuntu). The repository is the Pypi - Python Package Index, and packages are installed with pip or the easy_install script, which is part of Python's setuptools package.
As a rule of thumb, you should not use both the packages installed via pip/setuptools, and packages available to your distro (via apt-get, yum, urpmi, etc...) as they might conflict.
So, one of the less error prone way to deal with it is to have separate Python installs in your system - leave the python that came with the system for system scripts and such - on this python, make use of packages installed by your package manager only. And install other versions of Python (or even the same), to be run with "virtualenv"s - on these other install you install things with pip/setuptools only.
(And even if one opt to live boldly and not use virtualenvs, installing another python version on the same prefix (/usr, and even /usr/local) than your system's Python is a source to confusing errors and conflicts).
Note that the Debian - and Ubuntu - systems devised a way to run parallel official Python's in /usr, and to have apt-get to install Python packages to both Python versions at once. This mostly works, but they mess with Python's default directory hierarchy, and some applications fail to use Python in this way. (It is also a mess to find the module files themselves in a Debian or Ubuntu). So the above method apply as a recommendation even if your system do have more than one version of Python available on apt-get.
In short, once you have compiled your desired version of Python, do this:
- use your system's package manager to install "python-setuptools" and "python-virtualenv" (not sure if these are the actual package names).
- Use
virtualenvto create an environment from which you will use your different Python version - Activate your virtualenv, and install Python packages using
pipon it.
Virtualenv does feature a "--help" switch to help you, but you basically do:
Copy$ virtualenv -p <path-to-python-interpreter> <environment-dir>
$ source <environment-dir>/bin/activate
And there you are - all things using Python will "see" the interpreter in the virtualenv, due to environment variables set.
ubuntu 10.04 doesn't have a python2.7 package. You have to build 2.7 yourself. I did read an article about ubuntu releasing a python2.7 package when 12.04 came out but i'm not sure what the repository location is.
http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/
or:
Copysudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7
https://askubuntu.com/questions/101591/install-python-2-7-2-on-ubuntu-10-04-64-bit
this question has lots of answers online.
Ok after a lot of searching I decided to build Python from source, so I downloaded the compressed source tarball from the Python download page, now we need to install the build-essential package to be able to compile the source files:
apt-get install build-essential
also we need to install these development packages which are required for some Python modules:
libbz2-dev
libsqlite3-dev
libreadline-dev
zlib1g-dev
libncurses5-dev
libssl-dev
libgdbm-dev
next we extract the downloaded source file:
tar zxf Python-2.7.6.tgz
then we cd into the extracted directory:
cd Python-2.7.6
and follow the instructions on the Python docs:
./configure --prefix=/opt/python
make
make install # <- in the docs but don't execute: use checkinstall
I chose to install it under the directory /opt/python which I created before, also I used the checkinstall package to create a .deb file so I can uninstall easily later, so we install it first:
apt-get install checkinstall
and substitute the last line make install with:
checkinstall
now I have a new python installation in /opt/python/lib/python2.7 and the binary file is in /opt/python/bin/python2.7.
now I can run in the command line /opt/python/bin/python2.7 to use this Python version, also we can make a link to this executable so we don't type the full path, I named it python2.7.6.
ln -s /opt/python/bin/python2.7 /usr/local/bin/python2.7.6
also the directory /opt/python/bin will contain later other executables like pip and virtualenv or any other modules you install so we can add it to the PATH environment variable, edit ~/.profile and add this line:
PATH="$PATH:/opt/python/bin"
and run:
source ~/.profile
I appended the path to the end because it contains executable names like the ones in /usr/bin like python, python2 and python2.7 so we keep the higher priority for /usr/bin.
You probably are looking for virtualenv or pyenv or some other non-system-wide method to install Python. The method using APT (Advance Package Tool) and dpkg, ensures that all parts of the system are working in harmony, so you maybe want to install python in a separated path, hidden of all the other programs that you can call at will, which is the purpose of pyenv/virtualenv. This answers how to install the latest version of python without breaking the system.
BTW, you can check out the latest version of python that Debian in madison, while the latest version of python 2 at the date is the one you pointed out:
โ ~ apt-cache policy python
python:
Installed: 2.7.5-5
Candidate: 2.7.5-5
Version table:
*** 2.7.5-5 0
500 http://ftp.us.debian.org/debian/ testing/main i386 Packages
100 /var/lib/dpkg/status
(pythonbrew is not longer maintained).