Upgrading python on centos

How Do I Upgrade my Python on CentOS 8

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:

yum groupinstall 'development tools' -y && yum install wget openssl-devel bzip2-devel libffi-devel xz-devel -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:

Читайте также:  Java build class file

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

alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.9 1 && alternatives --set python3 /usr/local/bin/python3.9 && echo "2" | alternatives --config python

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:

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

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)

Источник

Установка Python 3.10 на CentOS 7/8

Определить текущую версию Python можно стандартной командой:

Или в системе может быть уже установлена альтернативная версия Python:

Узнать расположение пакета Python и его библиотек можно так:

python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /usr/include/python2.7 /usr/share/man/man1/python.1.gz

Установка из пакетов

Это самый просто и быстрый способ установки. Но на момент написания инструкции в репозитории epel доступн Python 3.6.

0. Подключаем репозиторий Epel:

# sudo yum install epel-release

1. Устанавливаем альтернативную версию с инструментами разработки и менеджером пакетов

# sudo yum install python3 python3-devel python3-pip

Менеджер попробует найти нужный пакет, если найдет, то выведет информацию и спросит про установку — вводим «y» и нажимаем ентер.

2. Проверяем установку. Данная версия будет доступна по алиасу:

3. Можно заменить стандартную версию, изменив символьную ссылку python с /usr/bin/python2 на /usr/bin/python3. Но перестанут работать некоторые пакеты, использующие Python (например, yum).

Установка из исходника

0.1. Устанавливаем из репозитория пакеты, необходимые для сборки пакетов:

# sudo yum install make gcc

gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)

Copyright (C) 2015 Free Software Foundation, Inc.

Это свободно распространяемое программное обеспечение. Условия копирования

приведены в исходных текстах. Без гарантии каких-либо качеств, включая

коммерческую ценность и применимость для каких-либо целей.

Устанавливаем инструменты необходимые для работы Python:

# sudo yum install openssl-devel libffi-devel bzip2-devel

0.2. Проверяем версию OpenSSL:

OpenSSL 1.0.2k-fips 26 Jan 2017

Обратите внимание, что для версий Python старше 3.7 требуется версия OpenSSL не ниже 1.1.1. Если вам требуется последняя версия Python и ваша версия ниже, то установите новую версию OpenSSL.

0.3. Проверяем версию SQLite:

3.38.2 2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f

Для свежих релизов Django требуется версия SQLite не ниже 3.9.0, если вы собираетесь использовать данную СУБД и ваша версия ниже, то произведите обновление SQLite.

1. Для работы менеджера пакетов Python (Pip) и модулей требуется библиотека OpenSSL. Ищем ее:

2. Переходим на официальный сайт https://www.python.org/downloads/, находим нужную версию, переходим на страницу этой версии и внизу страницы копируем ссылку на архив «Gzipped source tarball».

3. Переходим в какую то временную папку и скачиваем архив на CentOS:

5. Переходим в папку с исходником:

6. Конфигурируем пакет с подключением OpenSSL и SQLite:

# sudo ./configure —enable-optimizations —with-openssl=/etc/pki/tlsl

Появится большой список проверок:

checking build system type. x86_64-pc-linux-gnu

checking host system type. x86_64-pc-linux-gnu

checking for python3.10. python3.10

checking for —enable-universalsdk. no

checking for —with-universal-archs. no

checking whether the C compiler works. yes

checking for C compiler default output file name. a.out

checking for suffix of executables.

checking for —with-static-libpython. yes

checking for —disable-test-modules. no

configure: creating ./config.status

config.status: creating Makefile.pre

config.status: creating Misc/python.pc

config.status: creating Misc/python-embed.pc

config.status: creating Misc/python-config.sh

config.status: creating Modules/ld_so_aix

config.status: creating pyconfig.h

config.status: pyconfig.h is unchanged

7. Производим установку как дополнительную версию Python:

Опять появится большой список, в конце должны увидеть примерно следующее:

changing mode of /usr/local/bin/2to3-3.10 to 755

rm -r /usr/local/lib/python3.10/lib-dynload/__pycache__

/usr/bin/install -c -m 644 ./Misc/python.man \

if test «xupgrade» != «xno» ; then \

upgrade) ensurepip=»—altinstall —upgrade» ;; \

Looking in links: /tmp/tmpvgniqw9e

Installing collected packages: setuptools, pip

WARNING: Value for scheme.headers does not match. Please report this to

WARNING: Value for scheme.headers does not match. Please report this to

WARNING: The script pip3.10 is installed in ‘/usr/local/bin’ which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warning, use —no-warn-script-location.

Successfully installed pip-22.0.4 setuptools-57.4.0

WARNING: Running pip as the ‘root’ user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

Значит установка прошла успешно.

8. Проверяем установку. Сам Python:

Менеджер пакетов Pip тоже был успешно установлен, проверяем:

pip 22.0.4 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)

Проверить версию SSL в Python:

# python3 -c «import ssl; print(ssl.OPENSSL_VERSION)»

OpenSSL 1.0.2k-fips 26 Jan 2017

Возможные ошибки при установке

Модуль не может быть установлен

Где-то посередине вывода при установке Python может появится сообщение о том? что не удалось включить в сборку какой-то модуль:

INFO: Can’t locate Tcl/Tk libs and/or headers

Python build finished successfully!

The necessary bits to build these optional modules were not found:

_curses _curses_panel _hashlib

To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

The following modules found by detect_modules() in setup.py, have been

built by the Makefile instead, as configured by the Setup files:

Could not build the ssl module!

Python requires a OpenSSL 1.1.1 or newer

copying and adjusting /root//Python-3.10.4/Tools/scripts/pydoc3 -> build/scripts-3.10

В данном случае это OpenSSL, требуется обновить его.

Following modules built successfully but were removed because they could not be imported: _sqlite3

В данном случае не корректная библиотека (не сам пакет) SQLite — по обновлению тут.

Ошибка SSL при использовании PIP

# pip3.10 install —upgrade pip3.10

Defaulting to user installation because normal site-packages is not writeable

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Ошибка означает что в сборке используемой версии Python нет модуля OpenSSL, его или не включили при сборке (в последних версиях он отключен по умолчанию) или он не был включен из-за конфликта версии — установите новую версию OpenSSL.

Источник

Update Python 3 on CentOS

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

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

# yum groupinstall 'development tools' -y && yum install wget openssl-devel bzip2-devel libffi-devel xz-devel -y 
# wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz 
# cd Python-3.9.6 && ./configure --enable-optimizations 
# alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.9 1 && alternatives --set python3 /usr/local/bin/python3.9 && echo "2" | alternatives --config python 

2. Update Pip

# /usr/local/bin/python3.9 -m pip install --upgrade pip 
# alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.9 1 && alternatives --set pip /usr/local/bin/pip3.9 
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.

Источник

Installing the latest version of Python on CentOS

Python is the popular high-level programming language, which is universal, fast and used in many projects, including large ones.

Installing the fresh variant of the libraries for supporting Python language in CentOS operating system is not difficult, especially if you follow everything in stages. In this tutorial, we will build version 3.10.11 from sources.

Updating Operating System Packages

Before updating Python directly, we update the operating system. Navigate terminal then execute:

Updating the operating system

Installing Python on CentOS

To work with Python you need to install it on your computer, which can be a non-trivial task for Linux newbies. At this point, we’ll walk via the installation step by step and provide detailed tutorial with commands and descriptions of each step.

Installing additional packages

If your system does not have the «wget» module, execute the commands one after the other:

The result of successful command execution

For further work, you need to get packages:

After successfully completing the installation, let’s install the «Development Tools»

To continue, you must go to the directory:

Loading source files

We get the latest version from the Python.org website. Visiting it, under «Downloads\Source code» copy the download link we found and need. Then run in the terminal, pasting in the just copied link:

After downloading, you must retrieve the contents of the archive. You can use this command to do so:

Downloading and unpacking the archive with the source code

Navigate to the resulting Python-3.11.3 folder and install directly from the source code:

Complete the installation by executing the commands one after the other:

Make sure the update is successful by sending a line to the terminal:

If version 3.11.x of Python is displayed, then all previous steps have gone correctly! It is now possible to use the universal programming language for your own purposes.

Python version update

If you already have an earlier version of Python, follow the steps below.

Installing additional Python packages

In order to perform a Python version upgrade, a few new packages must be supplied in addition. Send commands to the terminal:

Installing additional packages

Установка дополнительных пакетов

sudo dnf install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

Installing additional packages

Loading source files

We get the latest version from the Python.org website. Visiting it, under «Downloads\Source code» copy the download link we found and need. Then run in the terminal, pasting in the just copied link:

After downloading, you must retrieve the contents of the archive. You can use this command to do so:

Downloading the archive with the source code

Update version

Navigate to the resulting Python-3.11.3 folder and install directly from the source code:

Check update

Make sure the update is successful by running the command:

Current version of python

If Python version 3.11.x is displayed then the update was successful.

Summary

In this review, we looked at «How to update Python on CentOS» by using source code files.

You may be interested in the following materials on the subject

Источник

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