Often encounter such a situation:
The system comes with Python is 2.x, they need Python 3.x, this time need to install multiple systems in Python, but can not affect the system comes with Python, ie the need to implement multiple versions of Python coexistence, pyenv is so a Python version manager.
-
Configuration version of the user's current python
-
The current configuration of python version shell
-
Configuring an item (directory and subdirectories) version of python
-
Configuring multiple virtual environments
yum -y installgcc zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel git
The automatic installer
Visit my other project: https://github.com/pyenv/pyenv-installer
git clone --depth 1"git://github.com/pyenv/pyenv.git" "${HOME}/.pyenv" git clone --depth 1"git://github.com/pyenv/pyenv-doctor.git" "${HOME}/.pyenv/plugins/pyenv-doctor" git clone --depth 1"git://github.com/pyenv/pyenv-installer.git" "${HOME}/.pyenv/plugins/pyenv-installer" git clone --depth 1"git://github.com/pyenv/pyenv-update.git" "${HOME}/.pyenv/plugins/pyenv-update" git clone --depth 1"git://github.com/pyenv/pyenv-virtualenv.git""${HOME}/.pyenv/plugins/pyenv-virtualenv" git clone --depth 1"git://github.com/pyenv/pyenv-which-ext.git" "${HOME}/.pyenv/plugins/pyenv-which-ext"
echo 'export PATH="/home/python/.pyenv/bin:$PATH"' >> ~/.bash_profile echo 'eval "$(pyenv init -)"' >> ~/.bash_profile echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile Source ~ / .bash_profile # View pyenv version pyevn - v # update pyenv pyenv Update
$ pyenv help Usage: pyenv <command> [<args>] Some useful pyenv commands are: commands List all available pyenv commands local Set or show the local application-specific Python version global Set or show the global Python version shell Set or show the shell-specific Python version install Install a Python version using python-build uninstall Uninstall a specific Python version rehash Rehash pyenv shims (run this after installing executables) version Show the current Python version and its origin versions List all Python versions available to pyenv which Display the full path to an executable whence List all Python versions that contain the given executable See `pyenv help <command>' for information on a specific command. For full documentation, see: https://github.com/pyenv/pyenv#readme
$pyenv install --help Usage: pyenv install [-f] [-kvp] <version> pyenv install [-f] [-kvp] <definition-file> pyenv install -l|--list pyenv install --version -l/--list List all available versions -f/--force Install even if the version appears to be installed already -s/--skip-existing Skip if the version appears to be installed already python-build options: -k/--keep Keep source tree in $PYENV_BUILD_ROOT after installation (defaults to $PYENV_ROOT/sources) -p/--patch Apply a patch from stdin before building -v/--verbose Verbose mode: print compilation status to stdout --version Show version of python-build -g/--debug Build a debug version For detailed information on installing Python versions with python-build, including a list of environment variables for adjusting compilation, see: https://github.com/pyenv/pyenv#readme $ pyenv install --list Available versions: 2.1.3 2.2.3 2.3.7 ……………… $ pyenv install 3.6.4 Downloading Python-3.6.4.tar.xz... -> https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz Installing Python-3.6.4... Installed Python-3.6.4 to /home/python/.pyenv/versions/3.6.4 $ pyenv install 3.5.4 Downloading Python-3.5.4.tar.xz... -> https://www.python.org/ftp/python/3.5.4/Python-3.5.4.tar.xz Installing Python-3.5.4... Installed Python-3.5.4 to /home/python/.pyenv/versions/3.5.4
# View the version that can be used, preceded by * indicates the currently used version pyenv versions # View the currently used version pyenv version $ pyenv versions * system (set by /home/python/.pyenv/version) 3.5.4 3.6.4 $ pyenv version system (set by /home/python/.pyenv/version)
-
pyenv global <version>
-
pyenv shelll <version>
-
pyenv local <version>
$ pyenv versions * system 3.5.4 3.6.4 (set by /home/python/.pyenv/version) For python $ - the V Python 2.6.6 $ pyenv global 3.6.4 $ pyenv versions system 3.5.4 * 3.6.4 (set by /home/python/.pyenv/version) For python $ - the V Python 3.6.4 $ for python - the V Python 3.6.4 $ exit logout # Log back $ Python - V Python 3.6.4
For python $ - the V Python 2.6.6 $ pyenv versions * system (set by /home/python/.pyenv/version) 3.5.4 3.6.4
$ pyenv shell 3.5.4
For python $ - the V Python 3.5.4 $ pyenv versions system * 3.5.4 (set by PYENV_VERSION environment variable) 3.6.4
$ pyenv shell --unset
$ mkdir project
$ cd project
$ pyenv local 3.6.4
$ pyenv versions system 3.5.4 * 3.6.4 (set by /home/python/project/.python-version) For python $ - the V Python 3.6.4
$ mkdir p_a&& cd p_a For python $ - the V Python 3.6.4 $ pyenv versions system 3.5.4 * 3.6.4 (set by /home/python/project/.python-version)
$ mkdir ../p_b&& cd ../p_b $ pyenv local system For python $ - the V Python 2.6.6 $ pyenv versions * system (set by /home/python/project/p_b/.python-version) 3.5.4 3.6.4
$ which python ~/.pyenv/shims/python $ which python3 ~/.pyenv/shims/python3 $ which pip3 ~/.pyenv/shims/pip3
#!/usr/bin/env bash set -e [ -n "$PYENV_DEBUG" ] && set -x program="${0##*/}" if [[ "$program" = "python"* ]]; then for arg; do case "$arg" in -c* | -- ) break ;; */* ) if [ -f "$arg" ]; then export PYENV_FILE_ARG="$arg" break be ;; esac done be export PYENV_ROOT="/home/python/.pyenv" exec "/home/python/.pyenv/libexec/pyenv" exec "$program" "$@"
-
If this variable PYENV_VERSION whether there is used a version of this variable; this variable is configured by pyenv shell <version> of;
-
Look up the root directory, the first one found among .python-version files as a version of the file that specifies the version as the version python order to find the parent directory; This document using pyenv local <version> Configuration
-
$ (Pyenv root) / version If this file exists, then use this file as a developed version of the python version; if not, use the version of the system; this file using pyenv global <version> Configuration
-
If the above variable or documents are not found, according to the system default python version developed by the.
1. Install pyenv:
1 1.> installation dependencies: 2 . 3 yum the install bzip2 zlib-devel-devel-devel OpenSSL the ncurses-devel SQLite the readline-devel devel-TK-gdbm-devel devel devel the libpcap-devel-DB4 an xz-devel - Y . 4 . 5 2 > installation package pyenv: . 6 . 7 Git clone https://github.com/pyenv/pyenv.git ~ / .pyenv . 8 . 9 3.> set the environment variables: 10 . 11 # Vim ~ / .bashrc 12 is Export PYENV_ROOT = " $ the HOME / .pyenv " 13 is Export the PATH = " $ PYENV_ROOT / bin: $ the PATH " 14 the eval " $ (pyenv the init -)" 15 16 # Source ~ / .bashrc 17 # That statement is a start, restart the system to execute this statement 18 Exec $ SHELL
2. Check the python version pyenv support, but also test has not been installed correctly:
1
|
pyenv install
-
-
list
|
3. Review all current versions pyenv detectable before the release of active marked with *.
1
2
3
4
|
[root@localhost ~]
# pyenv versions
system
3.5
.
1
*
3.5
.
3
(
set
by
/
root
/
.pyenv
/
version)
|
4. Check the version currently active in parentheses indicate the contents of this version is activated by Which pathway (global, local, shell)
1
2
|
[root@localhost ~]
# pyenv version
3.5
.
3
(
set
by
/
root
/
.pyenv
/
version)
|
5. 3.5.1 as global variables, the following command.
1
2
3
|
[root@localhost ~]
# pyenv global 3.5.1
[root@localhost ~]
# pyenv version
3.5
.
1
(
set
by
/
root
/
.pyenv
/
version)
|
6. The setup for the local version, write the current version number by .python-version files under the directory manner.
# Create a local directory ops, after performing pyenv local 3.5.3, only the directory is version 3.5.3, another directory using the default versions.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@localhost ~]
# python -V
Python
3.5
.
1
[root@localhost ~]
# pyenv versions
system
*
3.5
.
1
(
set
by
/
root
/
.pyenv
/
version)
3.5
.
3
[root@localhost ~]
#
[root@localhost ~]
# mkdir ops
[root@localhost ~]
# cd ops/
[root@localhost ops]
# pyenv local 3.5.3
[root@localhost ops]
# python -V
Python
3.5
.
3
[root@localhost ops]
# cd ..
[root@localhost ~]
# python -V
Python
3.5
.
1
|
7. Install Python versions (such as 3.4.0) you need:
1
2
3
|
pyenv install
3.4
.
0
-
v
#小技巧,可以在/root/.pyenv/目录下创建cache目录,将下载好的Python-3.4.0的包放在该目录下,就可以直接执行安装,而不需要下载,节省下载时间.
|
The need to update the database after the installation is complete:
1
|
pyenv rehash
|
9. Uninstall python 3.4.0 version.
1
|
pyenv uninstall
3.4
.
0
|