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.
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
Videos
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"
Beginners beware, this post isn't about overwriting the default python installation, but working with alternative installation of other versions of python on your Ubuntu 20. If you overwrite your default python you are likely to encounter several other issues that may cause you to reinstall your OS, so please go through the complete post and try to make alternate installation.
In this post, I am going to write about a way to install specific python version (python 3.7.5) in your Ubuntu 20 system which initially has Python 3.8. Since, the project I have done till now had the Python version of 3.6 and 3.7. But, after I updated my OS to Ubuntu 20, my virtual environment could not be set upped as per the project requirements.
Because I wanted my old projects to be compatible, first, I thought of way to override my python 3.8 with python 3.7 but had so many other issues.
Now, I have found a way to deal with this version issue, which I will be explaining below.
1 Checking, Initial version of Python that comes with Ubuntu 20
$ python3 --version Python 3.8.2
2 Installation of pip
a. First updating the packages
$ sudo apt update
b. Installation of pip
# The command below will install all the dependencies required for building Python modules. $ sudo apt install python3-pip
c. Verification of pip installed
$ pip3 --version pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
3 Install virtualenv in your local system
Virtualenv is where all the packages required for project will be kept without dealing with local system packages.
$ pip3 install virtualenv
If you want to use Python 3.8 in your project, then, below process can be followed.
# my_project is the project directory $ mkdir my_project && cd my_project # Create a virtual environment in your project directory $ python3 -m virtualenv .venv # Activating the environment $ source .venv/bin/activate $ python --version Python 3.8.2
But, this isn't our objective, we want to use other python version (Lets say Python 3.7.5). So, for that please see the below steps.
First install specific version of python in your local system without causing conflict in local system
# Update and Upgrades of packages $ sudo apt update $ sudo apt upgrade -y # Next, install the build tools and Python 3.7 dependencies using the following command: $ sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev # Next, download the source code of Python 3.7 using the wget tool: $ cd /tmp $ wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tar.xz # Next, decompress the tar file using: $ tar xf Python-3.7.5.tar.xz # Next, navigate inside your decompressed Python-3.7.0 folder: $ cd Python-3.7.5 # Build Python 3.7.5 code using the configure and make tools: $ ./configure --enable-optimizations $ sudo make -j 8 # Next, run the following command to install the Python 3.7.5: # Prefer "altinstall" than "install" because install will override the current OS python, and will cause other conflicts in OS. $ sudo make altinstall # Python 3.7.5 can run using: $ python3.7
After the specific version of python is installed successfully.
Create virtual environment in your project with specific version installed
# First know your specific python version installed path $ which python3.7 /usr/local/bin/python3.7 # my_project is a project directory $ mkdir my_project && cd my_project # Create virtualenv with the specific python version path $ python3 -m virtualenv --python=/usr/local/bin/python3.7 .venv # Activating the virtualenv $ source .venv/bin/activate # Test the python path and version $ which python my_project/.venv/bin/python # python --version Python 3.7.5
Now can work on any project as required.
Would like to get recommendation on this process, or any other ways it can be dealt with.
I am not so familiar with working with server but now i got an almalinux8
Virtualization: kvm Operating System: AlmaLinux 8.10 (Cerulean Leopard) CPE OS Name: cpe:/o:almalinux:almalinux:8::baseos Kernel: Linux 4.18.0-553.16.1.el8_10.x86_64 Architecture: x86-64
Next, I need to install python3.9 without changing the default version used by the whole system
python3 --version Python 3.6.8
and I see
sudo dnf module list | grep -i python [sudo] password for xxxx: libselinux-python 2.8 common Python 2 bindings for libselinux python27 2.7 [d] common [d] Python programming language, version 2.7 python36 3.6 [d][e] build, common [d] Python programming language, version 3.6 python38 3.8 [d] build, common [d] Python programming language, version 3.8 python39 3.9 [d] build, common [d] Python programming language, version 3.9 python38-devel 3.8 build, common Python programming language, version 3.8 python39-devel 3.9 build, common Python programming language, version 3.9
So my idea is enable, install and modify only my bash
sudo dnf module enable python39 sudo dnf install python39 #open ~/.bashrc # Add Python 3.9 to PATH export PATH="/usr/bin/python3.9:$PATH" alias python=python3.9
Is this the correct way to go? Am I missing something? Thanks and I am sorry for this basic question but I just start my journey to work with server.
All the answers here are outdated since Python.org doesn't host installers for older versions of Python anymore, only source code.
And building Python on Windows is not really a walk in the park...
My solution: Pyenv.
It's crossplatform (Linux, MacOS, Windows: where it's called pyenv-win), and you can with it automatically install among a very large list of Python versions.
There aren't ALL python versions existing but the list is already very big.
Installation pf pyenv is quite easy if you use chocolatey.
Then:
pyenv install --list : all the versions that you can install.
and then:
pyenv install 3.9.0 for example.
Python.org DOES host installers for older versions
For example if you want to download version 3.4 you just have to find major release which is:
https://www.python.org/ftp/python/3.4.4/
In case release is only bugfix you want be able to find installer so than just change last digit in url until you find release with installer, so
https://www.python.org/ftp/python/3.4.**x**/
change x until you find installer for your release.
Or, browse the parent folder and find the version you want:
https://www.python.org/ftp/python/
Optionally- than you can find latest bugfix and try to install it manually.
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.
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.
Alternatively, since pip itself is written in python, you can just call it with the python version you want to install the package for:
Copypython2.7 -m pip install foo
Use a version of pip installed against the Python instance you want to install new packages to.
In many distributions, there may be separate python2.6-pip and python2.7-pip packages, invoked with binary names such as pip-2.6 and pip-2.7. If pip is not packaged in your distribution for the desired target, you might look for a setuptools or easyinstall package, or use virtualenv (which will always include pip in a generated environment).
pip's website includes installation instructions, if you can't find anything within your distribution.
Update: In the modern (2020s) world, python -m pip is the right way to do this, where python can be replaced with whichever interpreter you choose.