Upgrading python on debian

Development

As you may know, Debian repositories update very slowly. At the time of writing, Python release versions are at 2.7.12 and 3.5.2, but in Debian 8 repositories you can find only 2.7.9 and 3.4.2. On Debian 7, versions in the repository are even older (2.7.3 and 3.2.3), both shipped in 2012.

This tutorial teaches you how to build Python from source and install the latest version. I assume you are using Debian 7 or 8. We will be obtaining the source code from the official Python FTP.

First, let’s check your currently installed version of Python. Run this command on your terminal:

You will see something like this:

Commands below must be performed by the root user.

Obtain Python source code

The following commands will load an archive with Python sources for version 2.7.12 to the home directory, unpack it, and switch to the directory with unpacked files:

cd /home wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz tar xf Python-2.7.12.tar.xz cd ./Python-2.7.12 

Pay attention to the name of the folder with unpacked files. It will be the same as the archive name (without the archive extension).

Читайте также:  Python string formatting percent

Compile Python

Now we can build the updated Python binaries:

./configure make make install 

Switch to the new version

If you check the Python version now, you still see the same old one. So we need to point the default Python interpreter path to the new python binary, which was installed to /usr/local/bin/python .

update-alternatives --install /usr/bin/python python /usr/local/bin/python 10 

Now you will see the installed version:

python --version Python 2.7.12 

Differences for Python 3

Python 3 can be updated in the same fashion, with one simple difference – you need to specify python3 instead of python . Note that Python 3 doesn’t come pre-installed on Debian 7.

update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3 10 

When updating Python 3, remember to choose a corresponding archive from the Python FTP site.

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!

Источник

Update Python 3 on Debian

This article explains how to install the latest version of Python3 from source code on Debian 10.

Prerequisites

1. Check the Installed Version

Check the installed Python3 version.

You will see something like this.

If your version is older than your application requires, proceed with this guide.

2. Update Python3

# apt-get install wget build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev liblzma-dev -y 
# wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz 
# cd Python-3.9.6 && ./configure --enable-optimizations 
# update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1 

2. Update Pip

# /usr/local/bin/python3.9 -m pip install --upgrade pip 
# update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.9 1 
Python 3.9.6 pip 21.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9) 

Conclusion

Keeping your Python up-to-date is an important part of the development process. It provides bug fixes compared to older versions, and more importantly, it introduces new features and optimizations.

Want to contribute?

You could earn up to $600 by adding new articles.

Источник

How Do I Upgrade my Python on Debian

In order to go to upgrade your python, you need to check its version. This can be done using the following command:

If python is successfully installed on your server, then you should get something like this:

Updating your Python Version

First, you need to install the required dependencies to compile the Python source code. This can be done using a special command, which is presented below:

# apt-get install wget build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev liblzma-dev -y

After that, we recommend going to the Python source download page to find the latest gzip version of the source code. Replace the urls and filenames in this tutorial with the latest version. Then download your python

wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz

After that, you need to unpack the archive that you just downloaded. You can do it like this:

Next, compile the Python source

cd Python-3.9.6 && ./configure --enable-optimizations

This is followed by the installation of your Python. Use the following command:

After that, a mandatory step for execution will be to check the name of your new Python executable file

Then Install the new default Python executable. Replace the two instances of /python3.9 in the following command with the name of your new Python executable

update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1

Update your PIP

An important step for this update is to update your pip.

/usr/local/bin/python3.9 -m pip install --upgrade pip

Then you should check the name of your new pip executable

Set the new item as default. Use the name of your new pip executable in the following command:

update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.9 1

After that, you need to check the current version of your installed Python. You can make sure like this:

After that, you will be able to see the following:

Python-3.9.6 pip 21.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

Источник

How to Update/Upgrade Python in Linux [Ubuntu/RedHat]

Update/Upgrade Python in Linux

This article will show you how to update Python to the latest version on your Linux Operating system.

Python is updated yearly with new features and big upgrades – these are called major updates. In addition to this, monthly updates are released which fix small issues and improve security – these are called minor updates.

Major updates change how Python works a bit and may break compatibility with some code as features are added or removed, whereas minor updates are solely there to fix problems without altering any functionality.

Updating From Python 2 to Python 3

Python 3 is still actively developed, receiving both minor and major updates. Python 2 is obsolete – it’s no longer developed, and you shouldn’t be using it for any new projects or to learn.

If you’re upgrading from Python 2 to Python 3, you will need to check your code is compatible – the syntax differs slightly between the two.

Python 2 and Python 3 are treated as separate software packages by most Linux package managers. To upgrade to version 3, simply install it.

The rest of this article will focus on the actively developed Python 3 only.

Install the Latest Version of Python on Ubuntu/Debian

On Ubuntu/Debian based distributions (including Mint, PopOS, etc) – run the following command:

This will install the default Python 3 version currently available on Ubuntu.

To install a specific version of Python 3, specify the full version:

sudo apt install python3.9

Install the Latest Version of Python on Fedora/RHEL

To install Python on RedHat based operating systems, run the following:

sudo dnf install python39

Note that the major version of Python 3 is always specified when installing using the dnf package manager – in this case, Python 3.9

Checking What Version of Python is Currently Installed

To check which version of Python you have installed, run:

Using a Package Manager to Upgrade Python Version

If Python 3 is already installed on your system, it will be updated along with the rest of your system when a software update is run.

sudo apt-get update sudo apt-get upgrade

Updating Minor/Major Versions

On Ubuntu/Debian based systems, Python will update to the default version available via the package manager. This is usually a bit behind the official release but is considered stable. This may include major releases if you have installed via the python3 package rather than a specific version.

On Fedora, only minor updates will be applied – you’ll need to install the next major release manually when it is available.

Источник

Оцените статью