[PYTHON] How is pyenv switching versions?

Introduction

I used ** pyenv ** ** pyenv **, a convenient tool for switching Python versions, and ** pyenv local ** without knowing the meaning, but suddenly [ When I looked at the pyenv page (https://github.com/yyuu/pyenv#how-it-works), I noticed that it carefully explained how it works. This is an abstract translation. Since it is an MIT license, I don't think you need a license, but please point out anything.

How pyenv works

** pyenv ** intercepts ** python ** commands in shim executables (** shim executables **), decides which Python version to run on, and has the correct Python installation for your application. Pass. The shim executable uses the ** PATH ** environment variable mechanism.

Understand PATH

When you run a command like ** python ** or ** pip **, the OS will take a series of directories with that name. Find the executable file. The list of directories is defined in the PATH environment variable with: (colon) A list of directories separated by.

--Find the ** pip ** executable file in the PATH environment variable --Find ** pip ** in the ** ~ / .pyenv / shims ** directory at the beginning of your PATH --Execute this ** pip ** and pass the command to ** pyenv **

** Python ** version selection

When running the sim, pyenv checks which Python version to use in the following order.

  1. The PYENV_VERSION environment variable (if defined). During the current shell session You can set this environment variable by using the ** pyenv shell ** command.

  2. A. ** python **-version file in the current directory (if it exists). You can change this with the ** pyenv local ** command.

  3. The. ** python **-version file in the parent directory. Go back to the route one by one. l

  4. Global ** ~ / .pyenv / version ** files. It can be changed with the ** pyenv global ** command.

  5. If none of the above is available ** "system" ** Python runs

Note: You can enable multiple versions at once, such as pyenv global 3.4.1 2.8.8. This is used when using ** python ** 2 and 3 in parallel, such as [tox](https://pypi. ** python **. Org / pypi / tox).

** Python ** installation location

When pyenv determines the version, it passes the command to the correct ** Python ** version. Each ** Python ** version is installed under ** ~ / .pyenv / versions **. For example, it looks like this.

in conclusion

As for pyenv, rbenv works in almost the same way. Next, I would like to examine pyenv and vritualenv, rbenv and bundler.

Recommended Posts

How is pyenv switching versions?
How to use Pyenv
Python version switching (pyenv)
How Python __dict__ is used
mkdocs: How HTML is generated
How to unlock pyenv global
How to uninstall pyenv itself
How to display a list of installable versions with pyenv
LowMemoryKiller ~ How Android Activity is destroyed ~
How to install Anaconda with pyenv