📦pyenv / pyenv
← 返回首页
Simple Python version management
⚖️ MIT#python#shell📅 创建于 2012-08-31🔄 更新于 2026-10-31
🔗 GitHub Shell

📄 仓库 README

在 GitHub 查看 ↗
来自 GitHub 仓库自述文件 · 版权归原作者所有

Simple Python Version Management: pyenv

Join the chat at https://gitter.im/yyuu/pyenv

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 and ruby-build, and modified for Python.

What pyenv does...

  • Lets you change the global Python version on a per-user basis.
  • Provides support for per-project Python versions.
  • Supports multiple Python distributions: CPython, PyPy, Stackless Python, Jython, and more. See the full list of available 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.

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 yourself, or pyenv-virtualenv to automate the process.

Table of Contents


Installation

A. Getting Pyenv


Linux/Unix

The Homebrew option from the [MacOS section below](#macos) would also work if you have Homebrew installed. ##### 1. Automatic installer (Recommended)
curl -fsSL https://pyenv.run | bash
For more details visit our other project: https://github.com/pyenv/pyenv-installer ##### 2. Basic GitHub Checkout This will get you going with the latest version of Pyenv and make it easy to fork and contribute any changes back upstream. * **Check out Pyenv where you want it installed.** A good place to choose is `$HOME/.pyenv` (but you can install it somewhere else): ``` git clone https://github.com/pyenv/pyenv.git ~/.pyenv ``` * Optionally, try to compile a dynamic Bash extension to speed up Pyenv. Don't worry if it fails; Pyenv will still work normally: ``` cd ~/.pyenv && src/configure && make -C src ```

MacOS

The options from the [Linux section above](#linuxunix) also work but Homebrew is recommended for basic usage. ##### [Homebrew](https://brew.sh) in macOS 1. Update homebrew and install pyenv: ```sh brew update brew install pyenv ``` If you want to install (and update to) the latest development head of Pyenv rather than the latest release, instead run: ```sh brew install pyenv --head ``` 3. Then follow the rest of the post-installation steps, starting with [Set up your shell environment for Pyenv](#b-set-up-your-shell-environment-for-pyenv). 4. 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 Python like Tkinter or NumPy _(This is only generally the case if you are a developer of such a formula, or if you have an EOL version of MacOS for which prebuilt bottles are no longer provided and you are using such a formula)._ To avoid them accidentally linking against a Pyenv-provided Python, add the following line into your interactive shell's configuration: * Bash/Zsh: ~~~bash alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew' ~~~ * Fish: ~~~fish alias brew="env PATH=(string replace (pyenv root)/shims '' \"\$PATH\") brew" ~~~

Windows

Pyenv does not officially support Windows and does not work in Windows outside the Windows Subsystem for Linux. Moreover, even there, the Pythons it installs are not native Windows versions but rather Linux versions running in a virtual machine -- so you won't get Windows-specific functionality. If you're in Windows, we recommend using @kirankotari's [`pyenv-win`](https://github.com/pyenv-win/pyenv-win) fork -- which does install native Windows Python versions.

B. Set up your shell environment for Pyenv


The below setup should work for the vast majority of users for common use cases. See Advanced configuration and specifically Manual shell setup for details and more configuration options.

To add the suggested setup code to the startup files of the running shell, run <path/to/pyenv> init --install. Specifically:

  • If you installed Pyenv with the installer script:
~/.pyenv/bin/pyenv init --install
  • If you installed Pyenv with Homebrew:
pyenv init --install

For Bash, avoid the automatic --install path if your BASH_ENV points to .bashrc; use the manual Bash instructions below so the eval "$(pyenv init - bash)" line only goes in your login startup file.

C. Restart your shell


for the PATH changes to take effect.

sh exec "$SHELL"

D. Install Python build dependencies


Install Python build dependencies before attempting to install a new Python version.

You can now begin using Pyenv.

E. Upgrade Notes


if you have upgraded from pyenv version 2.0.x-2.2.x

The startup logic and instructions have been updated for simplicity in 2.3.0. The previous, more complicated configuration scheme for 2.0.0-2.2.5 still works. * Define environment variable `PYENV_ROOT` to point to the path where Pyenv will store its data. `$HOME/.pyenv` is the default. If you installed Pyenv via Git checkout, we recommend to set it to the same location as where you cloned it. * Add the `pyenv` executable to your `PATH` if it's not already there * run `eval "$(pyenv init -)"` to install `pyenv` into your shell as a shell function, enable shims and autocompletion * You may run `eval "$(pyenv init --path)"` instead to just enable shims, without shell integration

Usage

Terminal output example

Install additional Python versions

To install additional Python versions, use pyenv install.

For example, to download and install Python 3.10.4, run:

pyenv install 3.10.4

Running pyenv install -l gives the list of all available versions.


Notes about python releases **NOTE:** Most Pyenv-provided Python releases are source releases and are built from source as part of installation (that's why you need Python build dependencies preinstalled). You can pass options to Python's `configure` and compiler flags to customize the build, see [_Special environment variables_ in Python-Build's README](https://github.com/pyenv/pyenv/blob/HEAD/plugins/python-build/README.md#special-environment-variables) for details. **NOTE:** If you are having trouble installing a Python version, please visit the wiki page about [Common Build Problems](https://github.com/pyenv/pyenv/wiki/Common-build-problems). **NOTE:** If you want to use proxy for download, please set the `http_proxy` and `https_proxy` environment variables. **NOTE:** If you'd like a faster interpreter at the cost of longer build times, see [_Building for maximum performance_ in Python-Build's README](https://github.com/pyenv/pyenv/blob/HEAD/plugins/python-build/README.md#building-for-maximum-performance).

Prefix auto-resolution to the latest version

All Pyenv subcommands except uninstall automatically resolve full prefixes to the latest version in the corresponding version line.

pyenv install picks the latest known version, while other subcommands pick the latest installed version.

E.g. to install and then switch to the latest 3.10 release:

pyenv install 3.10
pyenv global 3.10

You can run pyenv latest -k <prefix> to see how pyenv install would resolve a specific prefix, or [pyenv latest <prefix>](https://github.com/pyen

📈 近 7 天 Star 趋势

每日新增 Star(柱)与累计 Star(线)· 数据来自 GitHub

🏆 排名变化趋势

在各榜单中的排名历史(数字越小越靠前)

📋 历史上榜记录

每次快照的详细数据
日期 榜单 排名 周期新增 总 STAR