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:< Span class= "com" >//github.com/yyuu/pyenv.git ~/.pyenv$ echo ' export pyenv_root= "$HOME/.pyenv" ' >> ~/. ' export path= ' $PYENV _root/bin: $PATH "' >>< Span class= "pln" > ~/. "eval" $ (pyenv init-) "' >> ~/.exec $SHELL -l
Install Pythonto view the installable version
$ pyenv install --list
This command lists the Python versions that can be installed with pyenv, with only a few examples:
< Span class= "pun". 7.8 # Python 2 Latest version .< Span class= "lit" >4.1 # Python 3 Latest version anaconda -4.0. 0 # support python 2.6 and 2.7anaconda3- 4.0. 0 # support Python 3.3 and 3.4
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 openssl openssl-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:
$ pyenv install 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.
If the network is not very good, with pyenv download will be slow, you can execute the command, and then go to the ~/.pyenv/cache directory to see the file name to download, and then to the official website to download, and put the file in ~/.pyenv/cache Directory. PYENV will check the integrity of the file and will not download it again if it is confirmed correctly.
For the scientific research environment, it is recommended to install the Anaconda release, which is prepared for scientific calculations, pyenv install anaconda-4.0.0 python 2.x version, pyenv installed anaconda3-4.0.0 Install Python version 3.x;
Update Database
After the installation is complete, the database needs to be updated:
$ pyenv rehash
View the currently installed Python version
$ pyenv versions* system (set by /home/seisman/.pyenv/version).4.1
The asterisk indicates that the python that is being used by the system is currently in Use.
set the global Python version
$ Pyenv global 3.4. 1$ pyenv versionssystem* 3.4 1 (set by /home/ seisman/./version)
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
$ pythonPython 3.4.1 (Default, Sep 10 2014, 17:10:18)[Gcc4.4.7 20120313 ( red hat 4.4 7-1)] on Linuxtype "help" , "copyright" , "credits" or "license" for more 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;
Reference
- Https://github.com/yyuu/pyenv
The road of Linux System--python multi-version coexistence problem