Install pyenv,
Install pyenv
Bytes
Install the dependent environment (root User ):
Yum-y install make gcc patch gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel readline-devel
Install pyenv (Common User ):
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile$ exec "$SHELL"
View supported python versions:
$ pyenv install --list
Install a specific version:
[ocean@jenkins ~]$ pyenv install 3.6.2Downloading Python-3.6.2.tar.xz...-> https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xzInstalling Python-3.6.2...Installed Python-3.6.2 to /home/ocean/.pyenv/versions/3.6.2
[root@jenkins ~]# pyenv install 3.5.2pyenv: /root/.pyenv/versions/3.5.2 already existscontinue with installation? (y/N) yDownloading Python-3.5.2.tar.xz...-> https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xzInstalling Python-3.5.2...patching file Lib/venv/scripts/posix/activate.fishInstalled Python-3.5.2 to /root/.pyenv/versions/3.5.2
View the installed python version:
[ocean@jenkins py362]$ pyenv versions* system (set by /home/ocean/py362/.python-version) 3.5.2 3.6.2
OK. For simple use, you can view the help information:
[ocean@jenkins ~]$ pyenv helpUsage: 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 executableSee `pyenv help <command>' for information on a specific command.For full documentation, see: https://github.com/pyenv/pyenv#readme
How can I switch the python version?
Use the local command of pyenv:
[ocean@jenkins ~]$ tree .├── py352└── py3622 directories, 0 files
In the home directory, I created the corresponding directories according to the installed python version number. Let's test:
[ocean@jenkins ~]$ cd py352/[ocean@jenkins py352]$ python -VPython 2.7.5
If the local command of pyenv is not executed, the python version is the default version 2.7.5 of the system. Then we can use pyenv to switch the version:
[ocean@jenkins py352]$ pyenv local 3.5.2[ocean@jenkins py352]$ python -VPython 3.5.2
Directly becomes 3.5.2, and then we are returning to the pycharm Directory :,
[ocean@jenkins py352]$ cd ../py362[ocean@jenkins py362]$ python -VPython 2.7.5[ocean@jenkins py362]$ pyenv local 3.6.2[ocean@jenkins py362]$ python -VPython 3.6.2
Go back to the home directory and check the following:
[ocean@jenkins py362]$ cd [ocean@jenkins ~]$ python -VPython 2.7.5
Or the default python version.
[ocean@jenkins py362]$ ll /home/ocean/py362 -atotal 8drwxrwxr-x 2 ocean ocean 28 Sep 4 19:08 .drwx------ 6 ocean ocean 4096 Sep 4 19:08 ..-rw-rw-r-- 1 ocean ocean 6 Sep 4 19:04 .python-version[ocean@jenkins py362]$ cat .python-version 3.6.2
Pyenv is
.python-version
File to switch to a specific version of python. If you delete this file, the system returns to the default python program.
If you want to use the default python program in a specific python version directory, you can run the following command in a specific directory:
$ pyenv local system
In this way, you can switch between multiple versions of python.