Often encountered this situation:
- The python that comes with the system is 2.6 and needs some of the features in Python 2.7;
- The system comes with Python 2.x, it needs Python 3.x;
There is a need to install multiple Python in the system, but it does not affect the python that comes with the system, which requires multiple versions of Python to coexist. Pyenv is such a Python version manager.
Installing Pyenv
git clone git://github.com/yyuu/pyenv.git ~/.pyenv'export pyenv_root= "$HOME/.pyenv" ' >> ~/'export path= "$PYENV _root/bin: $PATH"' >> ~/ 'eval ' $ (pyenv init-) "' >> ~/-L
To view the installable version
Pyenv Install--list
This command lists the Python versions that can be installed with pyenv
One of the shapes, such as x.x.x , is the official version of the Python version, and the other shapes, such as xxxxx-x.x.x , are either "derivative" or "release" after the same name and version.
Install Python's dependency package
When you install Python, you need to first install the other packages it relies on, and some known libraries that require pre-installation are as follows.
Under the centos/Rhel/fedora:
sudo yum install readline readline-devel readline-staticsudo yum install OpenSSLOpenSSL-devel openssl-staticsudo yum install sqlite-develsudo yum install bzip2-devel bzip2-libs
Install the specified version
Use the following command to install Python 3.4.1:
3.4. 1 -V
The command downloads python's source code from GitHub, extracts it to the/tmp directory, and performs the compilation work in/tmp. If the dependent package is not installed, a compilation error occurs and the command needs to be re-executed after the dependent package is installed.
For the scientific research environment, it is recommended to install the Anaconda release, which is designed for scientific calculation,pyenv install anaconda-2.1.0 installation version 2.x, Pyenv installed anaconda3-2.1.0 installation of 3.x version;
Anacoda is very large, with pyenv download will be slow, you can go to the Anaconda official website to download, and the downloaded files in the ~/.pyenv/cache directory, then Pyenv will not be repeated download.
Update Database
After the installation is complete, the database needs to be updated:
Pyenv Rehash
View the currently installed Python version
Pyenv versions
The asterisk indicates that the python that is being used by the system is currently in use.
Set the global Python version
Global 3.4. 1
Pyenv versions
The current global Python version has become 3.4.1. You can also use the pyenv local or pyenv shell to temporarily change the Python version.
Confirm Python version
$ Pythonpython3.4.1(default, SepTen the, -:Ten: -) [GCC4.4.7 20120313(Red Hat4.4.7-1)] on Linuxtype" Help","Copyright","credits"Or"License" forMore information.>>>
Using Python
- Enter python to use the new version of Python;
- The system comes with a script that calls the old version of Python directly in a /usr/bin/python manner, and thus does not affect the system script;
- Installing a third-party module with PIP is installed under ~/.pyenv/versions/3.4.1 and does not conflict with the system module.
- After using pip to install the module, you may need to perform pyenv rehash update the database;
Python multi-version coexistence of pyenv