# Simple Python Version Management: pyenv
[![Join the chat at https://gitter.im/yyuu/pyenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/yyuu/pyenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
pyenv lets you easily switch between multiple versions of Python. It's
simple, unobtrusive, and follows the UNIX tradition of single-purpose
tools that do one thing well.
This project was forked from [rbenv](https://github.com/rbenv/rbenv) and
[ruby-build](https://github.com/rbenv/ruby-build), and modified for Python.
![Terminal output example](/terminal_output.png)
### what pyenv _does..._
* Lets you **change the global Python version** on a per-user basis.
* Provides support for **per-project Python versions**.
* Allows you to **override the Python version** with an environment
variable.
* Searches for commands from **multiple versions of Python at a time**.
This may be helpful to test across Python versions with [tox](https://pypi.python.org/pypi/tox).
### In contrast with pythonbrew and pythonz, pyenv _does not..._
* **Depend on Python itself.** pyenv was made from pure shell scripts.
There is no bootstrap problem of Python.
* **Need to be loaded into your shell.** Instead, pyenv's shim
approach works by adding a directory to your `$PATH`.
* **Manage virtualenv.** Of course, you can create [virtualenv](https://pypi.python.org/pypi/virtualenv)
yourself, or [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv)
to automate the process.
----
## Table of Contents
* **[How It Works](#how-it-works)**
* [Understanding PATH](#understanding-path)
* [Understanding Shims](#understanding-shims)
* [Choosing the Python Version](#choosing-the-python-version)
* [Locating the Python Installation](#locating-the-python-installation)
* **[Installation](#installation)**
* [Prerequisites](#prerequisites)
* [Homebrew in macOS](#homebrew-in-macos)
* [Windows](#windows)
* [Automatic installer](#automatic-installer)
* [Basic GitHub Checkout](#basic-github-checkout)
* [Upgrading](#upgrading)
* [Homebrew on macOS](#homebrew-on-macos)
* [Advanced Configuration](#advanced-configuration)
* [Uninstalling Python Versions](#uninstalling-python-versions)
* **[Command Reference](#command-reference)**
* **[Development](#development)**
* [Version History](#version-history)
* [License](#license)
----
## How It Works
At a high level, pyenv intercepts Python commands using shim
executables injected into your `PATH`, determines which Python version
has been specified by your application, and passes your commands along
to the correct Python installation.
### Understanding PATH
When you run a command like `python` or `pip`, your operating system
searches through a list of directories to find an executable file with
that name. This list of directories lives in an environment variable
called `PATH`, with each directory in the list separated by a colon:
/usr/local/bin:/usr/bin:/bin
Directories in `PATH` are searched from left to right, so a matching
executable in a directory at the beginning of the list takes
precedence over another one at the end. In this example, the
`/usr/local/bin` directory will be searched first, then `/usr/bin`,
then `/bin`.
### Understanding Shims
pyenv works by inserting a directory of _shims_ at the front of your
`PATH`:
$(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin
Through a process called _rehashing_, pyenv maintains shims in that
directory to match every Python command across every installed version
of Python—`python`, `pip`, and so on.
Shims are lightweight executables that simply pass your command along
to pyenv. So with pyenv installed, when you run, say, `pip`, your
operating system will do the following:
* Search your `PATH` for an executable file named `pip`
* Find the pyenv shim named `pip` at the beginning of your `PATH`
* Run the shim named `pip`, which in turn passes the command along to
pyenv
### Choosing the Python Version
When you execute a shim, pyenv determines which Python version to use by
reading it from the following sources, in this order:
1. The `PYENV_VERSION` environment variable (if specified). You can use
the [`pyenv shell`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell) command to set this environment
variable in your current shell session.
2. The application-specific `.python-version` file in the current
directory (if present). You can modify the current directory's
`.python-version` file with the [`pyenv local`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local)
command.
3. The first `.python-version` file found (if any) by searching each parent
directory, until reaching the root of your filesystem.
4. The global `$(pyenv root)/version` file. You can modify this file using
the [`pyenv global`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-global) command. If the global version
file is not present, pyenv assumes you want to use the "system"
Python. (In other words, whatever version would run if pyenv weren't in your
`PATH`.)
**NOTE:** You can activate multiple versions at the same time, including multiple
versions of Python2 or Python3 simultaneously. This allows for parallel usage of
Python2 and Python3, and is required with tools like `tox`. For example, to set
your path to first use your `system` Python and Python3 (set to 2.7.9 and 3.4.2
in this example), but also have Python 3.3.6, 3.2, and 2.5 available on your
`PATH`, one would first `pyenv install` the missing versions, then set `pyenv
global system 3.3.6 3.2 2.5`. At this point, one should be able to find the full
executable path to each of these using `pyenv which`, e.g. `pyenv which python2.5`
(should display `$(pyenv root)/versions/2.5/bin/python2.5`), or `pyenv which
python3.4` (should display path to system Python3). You can also specify multiple
versions in a `.python-version` file, separated by newlines.
Lines starting with a `#` are ignored.
### Locating the Python Installation
Once pyenv has determined which version of Python your application has
specified, it passes the command along to the corresponding Python
installation.
Each Python version is installed into its own directory under
`$(pyenv root)/versions`.
For example, you might have these versions installed:
* `$(pyenv root)/versions/2.7.8/`
* `$(pyenv root)/versions/3.4.2/`
* `$(pyenv root)/versions/pypy-2.4.0/`
As far as Pyenv is concerned, version names are simply directories under
`$(pyenv root)/versions`.
### Managing Virtual Environments
There is a pyenv plugin named [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv) which comes with various features to help pyenv users to manage virtual environments created by virtualenv or Anaconda.
Because the `activate` script of those virtual environments are relying on mutating `$PATH` variable of user's interactive shell, it will intercept pyenv's shim style command execution hooks.
We'd recommend to install pyenv-virtualenv as well if you have some plan to play with those virtual environments.
----
## Installation
### Prerequisites
For pyenv to install python correctly you should [**install the Python build dependencies**](https://github.com/pyenv/pyenv/wiki#suggested-build-environment).
### Homebrew in macOS
1. Consider installing with [Homebrew](https://brew.sh):
```sh
brew update
brew install pyenv
```
2. Then follow the rest of the post-installation steps under [Basic GitHub Checkout](https://github.com/pyenv/pyenv#basic-github-checkout), starting with #​2 ("Configure your shell's environment for Pyenv").
3. OPTIONAL. To fix `brew doctor`'s warning _""config" scripts exist outside your system or Homebrew directories"_
If you're going to build Homebrew formulae from source that link against `libpython`
like Tkinter or NumPy
_(This is only gene
没有合适的资源?快使用搜索试试~ 我知道了~
pyenv安装脚本pyenv.zip
共888个文件
patch:161个
0:104个
1:63个
需积分: 0 3 下载量 194 浏览量
2022-03-30
17:07:46
上传
评论
收藏 1.18MB ZIP 举报
温馨提示
pyenv安装脚本,github下载不了的可以下载
资源详情
资源评论
资源推荐
收起资源包目录
pyenv安装脚本pyenv.zip (888个子文件)
pypy-4.0.0 3KB
pypy-5.0.0 3KB
pypy2-5.6.0 3KB
pypy2.7-6.0.0 3KB
pypy3-2.4.0 3KB
pypy-2.5.0 3KB
pypy-2.6.0 3KB
pypy3.5-6.0.0 3KB
pypy3.5-5.10.0 3KB
pypy-2.4.0 3KB
pypy2-5.7.0 3KB
pypy2.7-5.10.0 2KB
pypy2.7-5.8.0 2KB
pypy2.7-5.9.0 2KB
pypy3.6-7.1.0 2KB
pypy3.5-7.0.0 2KB
pypy2.7-7.0.0 2KB
pypy2.7-7.1.0 2KB
pypy3.6-7.2.0 2KB
pypy2.7-7.2.0 2KB
graalpython-22.0.0 2KB
graalpython-21.0.0 2KB
graalpython-21.1.0 2KB
graalpython-20.1.0 2KB
graalpython-20.2.0 2KB
graalpython-20.3.0 2KB
graalpython-21.2.0 2KB
graalpython-21.3.0 2KB
pypy3.6-7.0.0 2KB
pypy3.6-7.3.0 2KB
pypy2.7-7.3.0 2KB
pypy-2.0 2KB
activepython-3.6.0 976B
miniconda2-3.19.0 938B
miniconda3-3.19.0 937B
miniconda3-3.16.0 937B
3.1.0 934B
3.2.0 934B
miniconda3-3.0.0 931B
miniconda3-3.7.0 931B
miniconda3-3.3.0 931B
miniconda-3.16.0 931B
miniconda-3.3.0 925B
miniconda-3.0.0 925B
anaconda3-5.0.0 924B
anaconda2-5.0.0 924B
3.10.0 922B
3.7.0 920B
3.8.0 920B
miniconda-3.7.0 919B
anaconda2-5.1.0 916B
anaconda3-5.1.0 916B
anaconda3-5.3.0 916B
anaconda3-4.4.0 916B
anaconda3-4.2.0 916B
anaconda3-5.2.0 916B
anaconda3-2.0.0 916B
anaconda3-4.3.0 916B
anaconda2-4.4.0 916B
anaconda3-2.1.0 916B
anaconda3-2.3.0 916B
anaconda2-4.3.0 916B
anaconda3-2.4.0 916B
anaconda2-2.5.0 916B
anaconda3-4.1.0 916B
anaconda2-4.2.0 916B
anaconda2-5.2.0 916B
anaconda3-2.5.0 916B
anaconda2-4.0.0 916B
anaconda3-4.0.0 916B
anaconda2-5.3.0 916B
anaconda2-4.1.0 916B
anaconda3-2.2.0 916B
anaconda2-2.4.0 916B
3.9.0 915B
anaconda-1.7.0 909B
anaconda-1.9.0 909B
anaconda-1.5.0 909B
anaconda-2.3.0 909B
anaconda-2.1.0 909B
anaconda-2.0.0 909B
anaconda-2.2.0 909B
anaconda-1.6.0 909B
anaconda-1.4.0 909B
anaconda-1.8.0 909B
pypy3.5-5.8.0 889B
pypy3.5-5.9.0 887B
miniconda3-3.7-4.11.0 883B
miniconda3-3.8-4.11.0 883B
miniconda3-3.9-4.11.0 883B
jython-2.5.0 870B
3.6.0 858B
3.5.0 858B
3.4.0 826B
2.5.0 729B
2.4.0 724B
2.7.0 607B
jython-2.7.0 604B
3.3.0 597B
2.6.0 591B
共 888 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
上帝De助手
- 粉丝: 1489
- 资源: 32
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0