pyenv

Содержание
Введение
Действия перед установкой Ubuntu/Debian/Mint
Установка в Ubuntu/Debian/Mint
.bashrc
Инструкция
Установить новый Python
Настройка после установки
Сменить версию Python
pyenv и virtualenv
Похожие статьи

Введение

Действия перед установкой в Ubuntu/Debian/Mint

Перед установкой pyenv нужно установить зависимости

sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

Hit:1 http://fi.archive.ubuntu.com/ubuntu focal InRelease Hit:2 http://fi.archive.ubuntu.com/ubuntu focal-updates InRelease Hit:3 http://fi.archive.ubuntu.com/ubuntu focal-backports InRelease Hit:4 http://dl.google.com/linux/chrome/deb stable InRelease Hit:5 http://archive.canonical.com/ubuntu focal InRelease Hit:6 https://download.docker.com/linux/ubuntu focal InRelease Hit:7 https://download.virtualbox.org/virtualbox/debian focal InRelease Hit:8 http://packages.microsoft.com/repos/code stable InRelease Hit:9 http://lenovo.archive.canonical.com focal InRelease Hit:10 https://packages.microsoft.com/repos/ms-teams stable InRelease Get:11 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] Hit:12 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/focal pgadmin4 InRelease Fetched 114 kB in 1s (125 kB/s) Reading package lists... Done Reading package lists... Done Building dependency tree Reading state information... Done libbz2-dev is already the newest version (1.0.8-2). libffi-dev is already the newest version (3.3-4). libncursesw5-dev is already the newest version (6.2-0ubuntu2). make is already the newest version (4.2.1-1.2). make set to manually installed. wget is already the newest version (1.20.3-1ubuntu1). wget set to manually installed. tk-dev is already the newest version (8.6.9+1). build-essential is already the newest version (12.8ubuntu1.1). curl is already the newest version (7.68.0-1ubuntu2.5). libsqlite3-dev is already the newest version (3.31.1-4ubuntu0.2). libssl-dev is already the newest version (1.1.1f-1ubuntu2.4). xz-utils is already the newest version (5.2.4-1ubuntu1). xz-utils set to manually installed. zlib1g-dev is already the newest version (1:1.2.11.dfsg-2ubuntu1.2). zlib1g-dev set to manually installed. The following package was automatically installed and is no longer required: libreadline5 Use 'sudo apt autoremove' to remove it. The following additional packages will be installed: binfmt-support icu-devtools libclang-cpp10 libgcrypt20-dev libgnutls-dane0 libgnutls-openssl27 libgnutls28-dev libgnutlsxx28 libgpg-error-dev libicu-dev libidn2-dev libnspr4-dev libnss3-dev libp11-kit-dev libpfm4 libtasn1-6-dev libtasn1-doc libunbound8 libxmlsec1-gcrypt libxmlsec1-gnutls libxmlsec1-openssl libxslt1-dev libz3-4 libz3-dev llvm-10 llvm-10-dev llvm-10-runtime llvm-10-tools llvm-runtime nettle-dev python3-pygments Suggested packages: libgcrypt20-doc gnutls-bin gnutls-doc icu-doc liblzma-doc readline-doc llvm-10-doc python-pygments-doc ttf-bitstream-vera The following packages will be REMOVED: libreadline-gplv2-dev The following NEW packages will be installed: binfmt-support icu-devtools libclang-cpp10 libgcrypt20-dev libgnutls-dane0 libgnutls-openssl27 libgnutls28-dev libgnutlsxx28 libgpg-error-dev libicu-dev libidn2-dev liblzma-dev libnspr4-dev libnss3-dev libp11-kit-dev libpfm4 libreadline-dev libtasn1-6-dev libtasn1-doc libunbound8 libxml2-dev libxmlsec1-dev libxmlsec1-gcrypt libxmlsec1-gnutls libxmlsec1-openssl libxslt1-dev libz3-4 libz3-dev llvm llvm-10 llvm-10-dev llvm-10-runtime llvm-10-tools llvm-runtime nettle-dev python3-pygments 0 upgraded, 36 newly installed, 1 to remove and 36 not upgraded. Need to get 64.7 MB of archives. After this operation, 371 MB of additional disk space will be used. Do you want to continue? [Y/n]

Y

Get:1 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 binfmt-support amd64 2.2.0-2 [58.2 kB] Get:2 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 icu-devtools amd64 66.1-2ubuntu2 [188 kB] Get:3 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 libclang-cpp10 amd64 1:10.0.0-4ubuntu1 [9,944 kB] Get:4 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libgpg-error-dev amd64 1.37-1 [109 kB] Get:5 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libgcrypt20-dev amd64 1.8.5-5ubuntu1 [470 kB] Get:6 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 libgnutls-openssl27 amd64 3.6.13-2ubuntu1.3 [29.8 kB] Get:7 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 libunbound8 amd64 1.9.4-2ubuntu1.2 [350 kB] Get:8 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 libgnutls-dane0 amd64 3.6.13-2ubuntu1.3 [29.1 kB] Get:9 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 libgnutlsxx28 amd64 3.6.13-2ubuntu1.3 [14.7 kB] Get:10 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libidn2-dev amd64 2.2.0-2 [64.6 kB] Get:11 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 libp11-kit-dev amd64 0.23.20-1ubuntu0.1 [65.2 kB] Get:12 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libtasn1-6-dev amd64 4.16.0-2 [85.8 kB] Get:13 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 nettle-dev amd64 3.5.1+really3.5.1-2ubuntu0.1 [987 kB] Get:14 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 libgnutls28-dev amd64 3.6.13-2ubuntu1.3 [873 kB] Get:15 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libicu-dev amd64 66.1-2ubuntu2 [9,450 kB] Get:16 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libnspr4-dev amd64 2:4.25-1 [206 kB] Get:17 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 libnss3-dev amd64 2:3.49.1-1ubuntu1.5 [231 kB] Get:18 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libreadline-dev amd64 8.0-4 [141 kB] Get:19 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libxml2-dev amd64 2.9.10+dfsg-5 [737 kB] Get:20 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libxmlsec1-gcrypt amd64 1.2.28-2 [41.5 kB] Get:21 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libxmlsec1-gnutls amd64 1.2.28-2 [33.4 kB] Get:22 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libxmlsec1-openssl amd64 1.2.28-2 [75.9 kB] Get:23 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libxslt1-dev amd64 1.1.34-4 [219 kB] Get:24 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libxmlsec1-dev amd64 1.2.28-2 [387 kB] Get:25 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 llvm-10-runtime amd64 1:10.0.0-4ubuntu1 [180 kB] Get:26 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 llvm-runtime amd64 1:10.0-50~exp1 [2,916 B] Get:27 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libpfm4 amd64 4.10.1+git20-g7700f49-2 [266 kB] Get:28 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 llvm-10 amd64 1:10.0.0-4ubuntu1 [5,214 kB] Get:29 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 llvm amd64 1:10.0-50~exp1 [3,880 B] Get:30 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 python3-pygments all 2.3.1+dfsg-1ubuntu2.2 [579 kB] Get:31 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 llvm-10-tools amd64 1:10.0.0-4ubuntu1 [317 kB] Get:32 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 libz3-4 amd64 4.8.7-4build1 [6,792 kB] Get:33 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 libz3-dev amd64 4.8.7-4build1 [67.5 kB] Get:34 http://fi.archive.ubuntu.com/ubuntu focal/universe amd64 llvm-10-dev amd64 1:10.0.0-4ubuntu1 [26.0 MB] Get:35 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 liblzma-dev amd64 5.2.4-1ubuntu1 [147 kB] Get:36 http://fi.archive.ubuntu.com/ubuntu focal/main amd64 libtasn1-doc all 4.16.0-2 [303 kB] Fetched 64.7 MB in 17s (3,855 kB/s) Extracting templates from packages: 100% (Reading database ... 358244 files and directories currently installed.) Removing libreadline-gplv2-dev:amd64 (5.2+dfsg-3build3) ... Selecting previously unselected package binfmt-support. (Reading database ... 358219 files and directories currently installed.) Preparing to unpack .../00-binfmt-support_2.2.0-2_amd64.deb ... Unpacking binfmt-support (2.2.0-2) ... Selecting previously unselected package icu-devtools. Preparing to unpack .../01-icu-devtools_66.1-2ubuntu2_amd64.deb ... Unpacking icu-devtools (66.1-2ubuntu2) ... Selecting previously unselected package libclang-cpp10. Preparing to unpack .../02-libclang-cpp10_1%3a10.0.0-4ubuntu1_amd64.deb ... Unpacking libclang-cpp10 (1:10.0.0-4ubuntu1) ... Selecting previously unselected package libgpg-error-dev. Preparing to unpack .../03-libgpg-error-dev_1.37-1_amd64.deb ... Unpacking libgpg-error-dev (1.37-1) ... Selecting previously unselected package libgcrypt20-dev. Preparing to unpack .../04-libgcrypt20-dev_1.8.5-5ubuntu1_amd64.deb ... Unpacking libgcrypt20-dev (1.8.5-5ubuntu1) ... Selecting previously unselected package libgnutls-openssl27:amd64. Preparing to unpack .../05-libgnutls-openssl27_3.6.13-2ubuntu1.3_amd64.deb ... Unpacking libgnutls-openssl27:amd64 (3.6.13-2ubuntu1.3) ... Selecting previously unselected package libunbound8:amd64. Preparing to unpack .../06-libunbound8_1.9.4-2ubuntu1.2_amd64.deb ... Unpacking libunbound8:amd64 (1.9.4-2ubuntu1.2) ... Selecting previously unselected package libgnutls-dane0:amd64. Preparing to unpack .../07-libgnutls-dane0_3.6.13-2ubuntu1.3_amd64.deb ... Unpacking libgnutls-dane0:amd64 (3.6.13-2ubuntu1.3) ... Selecting previously unselected package libgnutlsxx28:amd64. Preparing to unpack .../08-libgnutlsxx28_3.6.13-2ubuntu1.3_amd64.deb ... Unpacking libgnutlsxx28:amd64 (3.6.13-2ubuntu1.3) ... Selecting previously unselected package libidn2-dev:amd64. Preparing to unpack .../09-libidn2-dev_2.2.0-2_amd64.deb ... Unpacking libidn2-dev:amd64 (2.2.0-2) ... Selecting previously unselected package libp11-kit-dev:amd64. Preparing to unpack .../10-libp11-kit-dev_0.23.20-1ubuntu0.1_amd64.deb ... Unpacking libp11-kit-dev:amd64 (0.23.20-1ubuntu0.1) ... Selecting previously unselected package libtasn1-6-dev:amd64. Preparing to unpack .../11-libtasn1-6-dev_4.16.0-2_amd64.deb ... Unpacking libtasn1-6-dev:amd64 (4.16.0-2) ... Selecting previously unselected package nettle-dev:amd64. Preparing to unpack .../12-nettle-dev_3.5.1+really3.5.1-2ubuntu0.1_amd64.deb ... Unpacking nettle-dev:amd64 (3.5.1+really3.5.1-2ubuntu0.1) ... Selecting previously unselected package libgnutls28-dev:amd64. Preparing to unpack .../13-libgnutls28-dev_3.6.13-2ubuntu1.3_amd64.deb ... Unpacking libgnutls28-dev:amd64 (3.6.13-2ubuntu1.3) ... Selecting previously unselected package libicu-dev:amd64. Preparing to unpack .../14-libicu-dev_66.1-2ubuntu2_amd64.deb ... Unpacking libicu-dev:amd64 (66.1-2ubuntu2) ... Selecting previously unselected package libnspr4-dev. Preparing to unpack .../15-libnspr4-dev_2%3a4.25-1_amd64.deb ... Unpacking libnspr4-dev (2:4.25-1) ... Selecting previously unselected package libnss3-dev:amd64. Preparing to unpack .../16-libnss3-dev_2%3a3.49.1-1ubuntu1.5_amd64.deb ... Unpacking libnss3-dev:amd64 (2:3.49.1-1ubuntu1.5) ... Selecting previously unselected package libreadline-dev:amd64. Preparing to unpack .../17-libreadline-dev_8.0-4_amd64.deb ... Unpacking libreadline-dev:amd64 (8.0-4) ... Selecting previously unselected package libxml2-dev:amd64. Preparing to unpack .../18-libxml2-dev_2.9.10+dfsg-5_amd64.deb ... Unpacking libxml2-dev:amd64 (2.9.10+dfsg-5) ... Selecting previously unselected package libxmlsec1-gcrypt:amd64. Preparing to unpack .../19-libxmlsec1-gcrypt_1.2.28-2_amd64.deb ... Unpacking libxmlsec1-gcrypt:amd64 (1.2.28-2) ... Selecting previously unselected package libxmlsec1-gnutls:amd64. Preparing to unpack .../20-libxmlsec1-gnutls_1.2.28-2_amd64.deb ... Unpacking libxmlsec1-gnutls:amd64 (1.2.28-2) ... Selecting previously unselected package libxmlsec1-openssl:amd64. Preparing to unpack .../21-libxmlsec1-openssl_1.2.28-2_amd64.deb ... Unpacking libxmlsec1-openssl:amd64 (1.2.28-2) ... Selecting previously unselected package libxslt1-dev:amd64. Preparing to unpack .../22-libxslt1-dev_1.1.34-4_amd64.deb ... Unpacking libxslt1-dev:amd64 (1.1.34-4) ... Selecting previously unselected package libxmlsec1-dev. Preparing to unpack .../23-libxmlsec1-dev_1.2.28-2_amd64.deb ... Unpacking libxmlsec1-dev (1.2.28-2) ... Selecting previously unselected package llvm-10-runtime. Preparing to unpack .../24-llvm-10-runtime_1%3a10.0.0-4ubuntu1_amd64.deb ... Unpacking llvm-10-runtime (1:10.0.0-4ubuntu1) ... Selecting previously unselected package llvm-runtime. Preparing to unpack .../25-llvm-runtime_1%3a10.0-50~exp1_amd64.deb ... Unpacking llvm-runtime (1:10.0-50~exp1) ... Selecting previously unselected package libpfm4:amd64. Preparing to unpack .../26-libpfm4_4.10.1+git20-g7700f49-2_amd64.deb ... Unpacking libpfm4:amd64 (4.10.1+git20-g7700f49-2) ... Selecting previously unselected package llvm-10. Preparing to unpack .../27-llvm-10_1%3a10.0.0-4ubuntu1_amd64.deb ... Unpacking llvm-10 (1:10.0.0-4ubuntu1) ... Selecting previously unselected package llvm. Preparing to unpack .../28-llvm_1%3a10.0-50~exp1_amd64.deb ... Unpacking llvm (1:10.0-50~exp1) ... Selecting previously unselected package python3-pygments. Preparing to unpack .../29-python3-pygments_2.3.1+dfsg-1ubuntu2.2_all.deb ... Unpacking python3-pygments (2.3.1+dfsg-1ubuntu2.2) ... Selecting previously unselected package llvm-10-tools. Preparing to unpack .../30-llvm-10-tools_1%3a10.0.0-4ubuntu1_amd64.deb ... Unpacking llvm-10-tools (1:10.0.0-4ubuntu1) ... Selecting previously unselected package libz3-4:amd64. Preparing to unpack .../31-libz3-4_4.8.7-4build1_amd64.deb ... Unpacking libz3-4:amd64 (4.8.7-4build1) ... Selecting previously unselected package libz3-dev:amd64. Preparing to unpack .../32-libz3-dev_4.8.7-4build1_amd64.deb ... Unpacking libz3-dev:amd64 (4.8.7-4build1) ... Selecting previously unselected package llvm-10-dev. Preparing to unpack .../33-llvm-10-dev_1%3a10.0.0-4ubuntu1_amd64.deb ... Unpacking llvm-10-dev (1:10.0.0-4ubuntu1) ... Selecting previously unselected package liblzma-dev:amd64. Preparing to unpack .../34-liblzma-dev_5.2.4-1ubuntu1_amd64.deb ... Unpacking liblzma-dev:amd64 (5.2.4-1ubuntu1) ... Selecting previously unselected package libtasn1-doc. Preparing to unpack .../35-libtasn1-doc_4.16.0-2_all.deb ... Unpacking libtasn1-doc (4.16.0-2) ... Setting up libnspr4-dev (2:4.25-1) ... Setting up libgnutls-openssl27:amd64 (3.6.13-2ubuntu1.3) ... Setting up nettle-dev:amd64 (3.5.1+really3.5.1-2ubuntu0.1) ... Setting up libxmlsec1-openssl:amd64 (1.2.28-2) ... Setting up libtasn1-doc (4.16.0-2) ... Setting up libreadline-dev:amd64 (8.0-4) ... Setting up libclang-cpp10 (1:10.0.0-4ubuntu1) ... Setting up python3-pygments (2.3.1+dfsg-1ubuntu2.2) ... Setting up libz3-4:amd64 (4.8.7-4build1) ... Setting up libunbound8:amd64 (1.9.4-2ubuntu1.2) ... Setting up libpfm4:amd64 (4.10.1+git20-g7700f49-2) ... Setting up libgpg-error-dev (1.37-1) ... Setting up libxmlsec1-gcrypt:amd64 (1.2.28-2) ... Setting up binfmt-support (2.2.0-2) ... Created symlink /etc/systemd/system/multi-user.target.wants/binfmt-support.service → /lib/systemd/system/binfmt-support.service. Setting up icu-devtools (66.1-2ubuntu2) ... Setting up libgnutlsxx28:amd64 (3.6.13-2ubuntu1.3) ... Setting up libidn2-dev:amd64 (2.2.0-2) ... Setting up liblzma-dev:amd64 (5.2.4-1ubuntu1) ... Setting up libnss3-dev:amd64 (2:3.49.1-1ubuntu1.5) ... Setting up libxmlsec1-gnutls:amd64 (1.2.28-2) ... Setting up libtasn1-6-dev:amd64 (4.16.0-2) ... Setting up libicu-dev:amd64 (66.1-2ubuntu2) ... Setting up libp11-kit-dev:amd64 (0.23.20-1ubuntu0.1) ... Setting up libz3-dev:amd64 (4.8.7-4build1) ... Setting up libgnutls-dane0:amd64 (3.6.13-2ubuntu1.3) ... Setting up llvm-10-tools (1:10.0.0-4ubuntu1) ... Setting up llvm-10-runtime (1:10.0.0-4ubuntu1) ... Setting up libxml2-dev:amd64 (2.9.10+dfsg-5) ... Setting up libgcrypt20-dev (1.8.5-5ubuntu1) ... Setting up llvm-runtime (1:10.0-50~exp1) ... Setting up libgnutls28-dev:amd64 (3.6.13-2ubuntu1.3) ... Setting up libxslt1-dev:amd64 (1.1.34-4) ... Setting up llvm-10 (1:10.0.0-4ubuntu1) ... Setting up llvm-10-dev (1:10.0.0-4ubuntu1) ... Setting up llvm (1:10.0-50~exp1) ... Setting up libxmlsec1-dev (1.2.28-2) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ... Processing triggers for systemd (245.4-4ubuntu3.6) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for install-info (6.7.0.dfsg.2-5) ...

Если не установлен curl выполните

sudo apt-get install curl

Установка в Ubuntu/Debian/Mint

Теперь нужно воспользоваться https://github.com/pyenv/pyenv-installer

curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 148 100 148 0 0 813 0 --:--:-- --:--:-- --:--:-- 817 100 1687 100 1687 0 0 3799 0 --:--:-- --:--:-- --:--:-- 3799 Cloning into '/home/andrei/.pyenv'... remote: Enumerating objects: 762, done. remote: Counting objects: 100% (762/762), done. remote: Compressing objects: 100% (396/396), done. remote: Total 762 (delta 417), reused 479 (delta 271), pack-reused 0 Receiving objects: 100% (762/762), 412.48 KiB | 3.93 MiB/s, done. Resolving deltas: 100% (417/417), done. Cloning into '/home/andrei/.pyenv/plugins/pyenv-doctor'... remote: Enumerating objects: 11, done. remote: Counting objects: 100% (11/11), done. remote: Compressing objects: 100% (9/9), done. remote: Total 11 (delta 1), reused 5 (delta 0), pack-reused 0 Unpacking objects: 100% (11/11), 38.62 KiB | 941.00 KiB/s, done. Cloning into '/home/andrei/.pyenv/plugins/pyenv-installer'... remote: Enumerating objects: 16, done. remote: Counting objects: 100% (16/16), done. remote: Compressing objects: 100% (13/13), done. remote: Total 16 (delta 1), reused 7 (delta 0), pack-reused 0 Unpacking objects: 100% (16/16), 5.74 KiB | 653.00 KiB/s, done. Cloning into '/home/andrei/.pyenv/plugins/pyenv-update'... remote: Enumerating objects: 10, done. remote: Counting objects: 100% (10/10), done. remote: Compressing objects: 100% (6/6), done. remote: Total 10 (delta 1), reused 6 (delta 0), pack-reused 0 Unpacking objects: 100% (10/10), 2.77 KiB | 708.00 KiB/s, done. Cloning into '/home/andrei/.pyenv/plugins/pyenv-virtualenv'... remote: Enumerating objects: 57, done. remote: Counting objects: 100% (57/57), done. remote: Compressing objects: 100% (51/51), done. remote: Total 57 (delta 11), reused 20 (delta 0), pack-reused 0 Unpacking objects: 100% (57/57), 35.52 KiB | 3.55 MiB/s, done. Cloning into '/home/andrei/.pyenv/plugins/pyenv-which-ext'... remote: Enumerating objects: 10, done. remote: Counting objects: 100% (10/10), done. remote: Compressing objects: 100% (6/6), done. remote: Total 10 (delta 1), reused 6 (delta 0), pack-reused 0 Unpacking objects: 100% (10/10), 2.92 KiB | 597.00 KiB/s, done. WARNING: seems you still have not added 'pyenv' to the load path. # (The below instructions are intended for common # shell setups. See the README for more guidance # if they don't apply and/or don't work for you.) # Add pyenv executable to PATH and # enable shims by adding the following # to ~/.profile: export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)" # If your ~/.profile sources ~/.bashrc, # the lines need to be inserted before the part # that does that. See the README for another option. # If you have ~/.bash_profile, make sure that it # also executes the above lines -- e.g. by # copying them there or by sourcing ~/.profile # Load pyenv into the shell by adding # the following to ~/.bashrc: eval "$(pyenv init -)" # Make sure to restart your entire logon session # for changes to profile files to take effect. # Load pyenv-virtualenv automatically by adding # the following to ~/.bashrc: eval "$(pyenv virtualenv-init -)"

.bashrc

Из инструкции следует, что нужно обновить файл .bashrc

vi ~/.bashrc

export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"

exec $SHELL

Если появилось предупреждение

WARNING: `pyenv init -` no longer sets PATH. Run `pyenv init` to see the necessary changes to make to your configuration.

Замените строку

eval "$(pyenv init -)"

На

eval "$(pyenv init --path)"

Инструкция

Изучить версию pyenv и доступные команды можно выполнив

pyenv

pyenv 2.0.1 Usage: pyenv <command> [<args>] Some useful pyenv commands are: activate Activate virtual environment commands List all available pyenv commands deactivate Deactivate virtual environment doctor Verify pyenv installation and development tools to build pythons. exec Run an executable with the selected Python version global Set or show the global Python version(s) help Display help for a command hooks List hook scripts for a given pyenv command init Configure the shell environment for pyenv install Install a Python version using python-build local Set or show the local application-specific Python version(s) prefix Display prefix for a Python version rehash Rehash pyenv shims (run this after installing executables) root Display the root directory where versions and shims are kept shell Set or show the shell-specific Python version shims List existing pyenv shims uninstall Uninstall a specific Python version --version Display the version of pyenv version Show the current Python version(s) and its origin version-file Detect the file that sets the current pyenv version version-name Show the current Python version version-origin Explain how the current Python version is set versions List all Python versions available to pyenv virtualenv Create a Python virtualenv using the pyenv-virtualenv plugin virtualenv-delete Uninstall a specific Python virtualenv virtualenv-init Configure the shell environment for pyenv-virtualenv virtualenv-prefix Display real_prefix for a Python virtualenv version virtualenvs List all Python virtualenvs found in `$PYENV_ROOT/versions/*'. whence List all Python versions that contain the given executable which Display the full path to an executable See `pyenv help <command>' for information on a specific command. For full documentation, see: https://github.com/pyenv/pyenv#readme

Установить новый Python

Список доступных для установки через pyenv версий можно получить выполнив

pyenv install --list

Версий очень много, поэтому советую воспользоваться grep

pyenv install --list | grep "3\.[8|9]"

3.8.0 3.8-dev 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.8.10 3.9.0 3.9-dev 3.9.1 3.9.2 3.9.3 3.9.4 3.9.5 miniconda-3.8.3 miniconda-3.9.1 miniconda3-3.8.3 miniconda3-3.8-4.8.2 miniconda3-3.8-4.8.3 miniconda3-3.8-4.9.2 miniconda3-3.9.1 miniconda3-3.9-4.9.2

Установить нужную версию (я выбрал 3.9.5) можно командой

pyenv isntall 3.9.5

Downloading Python-3.9.5.tar.xz... -> https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tar.xz Installing Python-3.9.5... Installed Python-3.9.5 to /home/andrei/.pyenv/versions/3.9.5

Настройка после установки

После установки по умолчанию будет по прежнему системный Pyhton 2.7

python

Python 2.7.18 (default, Mar 8 2021, 13:02:45) [GCC 9.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information.

ll ~/.pyenv/versions

total 12 drwxr-xr-x 3 andrei urnsu 4096 Jun 15 15:36 ./ drwxr-xr-x 13 andrei urnsu 4096 Jun 15 15:12 ../ drwxr-xr-x 6 andrei urnsu 4096 Jun 15 15:32 3.9.5/

vi ~/.pyenv/version

3.9.5

python -V

3.9.5

which python

/home/andrei/.pyenv/shims/python

pyenv versions

system * 3.9.5 (set by /home/andrei/.pyenv/version)

pyenv which python

/home/andrei/.pyenv/versions/3.9.5/bin/python

Сменить версию Python

Проверить текущую global версию можно выполнив

pyenv versions

* system (set by /home/andrei/.pyenv/version) 3.9.9

Доступно две версии: системный Python (является глобальным в данный момент) и установленный мной через pyenv 3.9.9

Сделать глобальным версию 3.9.9 можно с помощью pyenv global

pyenv global 3.9.9
pyenv versions

system (set by /home/andrei/.pyenv/version) * 3.9.9

pyenv virtualenv

Создать новое виртуальное окружение

pyenv virtualenv 3.9.5 sdk_pyenv

Проверить создалось ли окружение можно выполнив

ls /home/andrei/.pyenv/versions/3.9.5/envs/

sdk_pyenv

Активировать окружение можно выполнив

pyenv local sdk_pyenv

После активации окружения в текущей директории будет создан файл .python-version

cat .python-version

sdk_pyenv

Проверить откуда теперь доступен Python

pyenv which python

/home/andrei/.pyenv/versions/sdk_pyenv/bin/python

Похожие статьи
Виртуальное окружение
Anaconda
venv
virtualenv

Поиск по сайту

Подпишитесь на Telegram канал @aofeed чтобы следить за выходом новых статей и обновлением старых

Перейти на канал

@aofeed

Задать вопрос в Телеграм-группе

@aofeedchat

Контакты и сотрудничество:
Рекомендую наш хостинг beget.ru
Пишите на info@urn.su если Вы:
1. Хотите написать статью для нашего сайта или перевести статью на свой родной язык.
2. Хотите разместить на сайте рекламу, подходящую по тематике.
3. Реклама на моём сайте имеет максимальный уровень цензуры. Если Вы увидели рекламный блок недопустимый для просмотра детьми школьного возраста, вызывающий шок или вводящий в заблуждение - пожалуйста свяжитесь с нами по электронной почте
4. Нашли на сайте ошибку, неточности, баг и т.д. ... .......
5. Статьи можно расшарить в соцсетях, нажав на иконку сети: