Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sergey-glushakov/fc5e63577505639e354b3b93f21740cf to your computer and use it in GitHub Desktop.

Select an option

Save sergey-glushakov/fc5e63577505639e354b3b93f21740cf to your computer and use it in GitHub Desktop.
Install Python 3.10 on Debian 11 Debian 10 ( Установка последней версии Python в Debian 10 or 11)

Что необходимо для установки последней версии Python на операционную систему Debian:

  1. Установленная операционная система Debian 11|10

  2. Пользователь с привилегиями sudo.

  3. Обновить систему

         sudo apt update && sudo apt upgrade
    
  4. Нужно установить необходимые зависимости, чтобы иметь возможность собрать Python 3.10 из исходного кода.

         sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
    
  5. Затем загрузите Python 3.10 с официальной страницы выпуска Python https://www.python.org/downloads/source/ . Находясь на этой странице, загрузите tar-архив Python 3.10 Gzippeed . В качестве альтернативы, получите ссылку для скачивания и извлеките ее с помощью Wget, как показано ниже:

         wget https://www.python.org/ftp/python/3.10.5/Python-3.10.5.tgz
    
  6. Загрузив архив, распакуйте его, как показано ниже. tar -xf Python-3.10.*.tgz

  7. Перейдите в извлеченный каталог и запустите команду configure, чтобы проверить, доступны ли необходимые зависимости. В команде флаг –enable-optimizations используется для оптимизации бинарного файла и запуска нескольких тестов

ВАЖНО!!! Для того чтобы собираемый проект не был разбросан по всей системе нужно указать параметр --prefix=/home/username/.python3.10

        cd Python-3.10.*/
        ./configure --enable-optimizations --prefix=/home/your_username/.python3.10

Пример вывода:

        cchecking build system type... x86_64-pc-linux-gnu
        checking host system type... x86_64-pc-linux-gnu
        checking for python3.10... no
        checking for python3... python3
        checking for --enable-universalsdk... no
        checking for --with-universal-archs... no
        checking MACHDEP... "linux"
        checking for gcc... gcc
        checking whether the C compiler works... yes
        checking for C compiler default output file name... a.out
        checking for suffix of executables...
        .........
        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
        creating Modules/Setup.local
        creating Makefile

Когда проверка будет завершена, соберите Python 3.10 из исходного кода, как показано ниже. Не забудьте ускорить процесс, используя флаг -j. Это указывает количество ядер в вашей системе. nproc Команда показывает ядра вашей системы.

        make -j 4

Пример вывода:

        .................
        changing mode of build/scripts-3.10/pydoc3 from 644 to 755
        changing mode of build/scripts-3.10/idle3 from 644 to 755
        changing mode of build/scripts-3.10/2to3 from 644 to 755
        renaming build/scripts-3.10/pydoc3 to build/scripts-3.10/pydoc3.10
        renaming build/scripts-3.10/idle3 to build/scripts-3.10/idle3.10
        renaming build/scripts-3.10/2to3 to build/scripts-3.10/2to3-3.10
        gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -fno-semantic-interposition -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -fprofile-use -fprofile-correction -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Programs/_testembed.o ./Programs/_testembed.cgcc -pthread   -fno-semantic-interposition  -Xlinker -export-dynamic -o Programs/_testembed Programs/_testembed.o libpython3.10.a -lcrypt -lpthread -ldl  -lutil -lm   -lm 
        make[1]: Leaving directory '/home/klinsmann/Python-3.10.0'

После завершения make продолжите установку Python 3.10 на Debian 11|10, как показано ниже.

        sudo make altinstall

Флаг altinstall используется для сохранения двоичного пути Python по умолчанию в /usr/bin/python

Вывод:

        Looking in links: /tmp/tmpjgyu604w
        Processing /tmp/tmpjgyu604w/setuptools-57.4.0-py3-none-any.whl
        Processing /tmp/tmpjgyu604w/pip-21.2.3-py3-none-any.whl
        Installing collected packages: setuptools, pip
        WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
        distutils: /usr/local/include/python3.10/setuptools
        sysconfig: /home/klinsmann/Python-3.10.0/Include/setuptools
        WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
        distutils: /usr/local/include/python3.10/pip
        sysconfig: /home/klinsmann/Python-3.10.0/Include/pip
        Successfully installed pip-21.2.3 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

Чтобы запускалась наша версия python необходимо указать путь к python в файле .bashrc отредактировав его:

        nano ~/.bashrc

Вставляем в конец файла .bashrc следующую строку:

        export PATH=$PATH:/home/YOUR_USERNAME/.python3.10/bin/

Перечитаем файл bashrc :

        source ~/.bashrc

Все, теперь при вводе команды python3.10

Мы получаем:

        Python 3.10.5 (main, Jul  8 2022, 20:22:04) [GCC 10.2.1 20210110] on linux
        Type "help", "copyright", "credits" or "license" for more information.
        >>> 

После очищаем в домашней директории ранее распакованные исходники

    sudo rm -rf Python-3.10.4.tgz Python-3.10.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment