Refer to the website
zhuanlan.zhihu.com/p/36402791
www.jianshu.com/p/20cd2fc91…
www.jianshu.com/p/1842a3632…
1/ Problem scenario:
<1> The Python interpreter version is messy, <2> Different Linux distributions ship with Python, such as Ubuntu16, which ships with versions 2.7 and 3.5. Many components of the system rely on the native interpreter. Deletion or change can cause problems for the system. Management of packages (extensions) for python versions <3 is also a problem, with essential package components such as PIP and ipython, as well as ensuring that different package environments do not interfere with each other during project development. Is there an ultimate solution to managing different interpreter versions while controlling different package environments? Yes, it is pyenv.Copy the code
What is 2/pyenv? What can you do?
Python versions are as follows: 2.7.x 3.x Anaconda2 Anaconda3 Pyenv is a python manager. You can keep multiple Versions of Python on your system at the same time. Give different names to different versions of Python. Different projects use different versions of Python as interpreters. Pyenv is a Python environment management tool that makes it easy to switch between global interpreter versions and manage packages with the Vitualenv plugin. As we know, when a command such as' ls' is entered in terminal, the shell will check whether the executable file ls exists in each directory in the PATH of the current environment, and execute it if it finds it; otherwise, the error 'Command no found' will be reported. Similarly, pyenv controls python versions by inserting the shims PATH in the PATH header.Copy the code
3/ Pyenv and Pipenv,virtualenv
Pipenv is a Python virtual environment management tool that combines the features of PIP and VirtualEnv with a focus on package management. The idea is to create an environment that specifies the Python version, and then install the package on that environment. Virtualenv is a traditional and mature virtual environment management tool, which is used by many people. Create a virtual environment and install the corresponding package. To enter the environment, source the activate script to activate it. Although mature, I personally don't like using PyEnv, and it is prone to environmental issues when deploying projects. Pyenv is relatively unknown, but it is stable, and I have used all three environmental management tools, I personally prefer PyEnv for the following reasons: <1> Compared to the other two tools, PyEnv focuses more on Python interpreter version management, a higher level than package management. Using PyEnv I can easily download a specific version of the Python interpreter, <2> The python interpreter can be switched locally and globally in the shell environment at any time. <3> The Python interpreter can be switched locally and globally in the shell environment at any time. PIP and ipython and their extensions switch together, so it's handy if you're running multiple interpreters ipython2.x and ipython3.x at the same time to validate some code. <4> PyEnv can also create a specific virtual environment, but it doesn't need to specify a specific directory. Easy to useCopy the code
4 / pyenv installation
<1> If it is a Clone project on a Linux server at home directory: $git clone https://github.com/pyenv/pyenv.git ~ /. Pyenv # if is MacOS local brew the update can be installed directly with homebrew $$brew install pyenv <2> Add Add the following to the shell configuration file: (e.g. ~/.zshrc file, ~/. Bash_profile file) export PYENV_ROOR="$HOME/. Pyenv "export PATH=$PYENV_ROOT/shims:$PATH eval "$(Pyenv Init -)" eval "$(pyenv virtualenv-init -)" <3>source pyenv --versionCopy the code
5/ Simple use
Pyenv install --list pyenv install --list pyenv install --list pyenv For example, pyenv install anaconda2-4.2.0Copy the code
Pyenv rehash pyenv rehash pyenv uninstall 3.5.2 pyenv Global Pyenv Global 3.6.5 2.7.14 pyenv Global 3.6.5 2.7.14 pyenv Global 3.6.5 2.7.14Copy the code
6/ Package management plugin pyenv-virtualenv
For Linux servers: $ git clone https://github.com/pyenv/pyenv-virtualenv.git $.pyenv/plugins/pyenv-virtualenv ZSHRC $echo 'eval "$(Pyenv Virtualenv-init -)"' >> ~/. Bash_profile $brew install pyenv-virtualenv $eval "$(Pyenv init -)" "$eval "$(Pyenv virtualenv-init -)" # create v365env = v365env # create v365env = v365env ~/. Pyenv /versions/ $PyEnv virtualenv 3.6.5 v365env $PyEnv deactivate v365env # Delete pyEnv virtualenv-delete v365env Pips and package libraries are also switched when the Python interpreter is switched, and virtual environments can be created for a given version of the interpreter. Switching is also extremely easy. When entering the environment, you can wave freely without worrying about affecting other projects. Pycharm works even better.Copy the code
Similarities and differences between PyEnv and Conda
Conda is both an environment manager and an extension package manager, which is similar. Conda comes with Anaconda, so you can run conda directly in the bin directory of Anacnoda without additional installation.Copy the code
conclusion
Pyenv can in different versions of python installed in the system, such as python2.7 python3.5, anaconda2, anaconda3, miniconda2 etc. Different versions of the interpreter. Then, with the Pyenv-VirtualEnv plug-in, you can create a virtual environment that specifies the version of Python as the interpreter. Environments can be created, activated, switched, and deleted at will.Copy the code