2012-08-31 06:23:41 +00:00
# Simple Python Version Management: pyenv
2015-09-21 02:43:40 +00:00
[![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)
2012-08-31 06:23:41 +00:00
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.
2015-11-28 03:12:54 +00:00
This project was forked from [rbenv ](https://github.com/rbenv/rbenv ) and
[ruby-build ](https://github.com/rbenv/ruby-build ), and modified for Python.
2012-08-31 06:23:41 +00:00
2018-02-22 14:43:44 +00:00
![Terminal output example ](/terminal_output.png )
2014-03-19 19:00:54 +00:00
2012-08-31 11:59:24 +00:00
2022-04-03 22:08:49 +00:00
### What pyenv _does..._
2012-08-31 06:23:41 +00:00
2021-10-23 14:33:18 +00:00
* 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
2012-08-31 06:23:41 +00:00
variable.
2021-10-23 14:33:18 +00:00
* Searches for commands from **multiple versions of Python at a time** .
2015-11-28 03:12:54 +00:00
This may be helpful to test across Python versions with [tox ](https://pypi.python.org/pypi/tox ).
2012-08-31 06:23:41 +00:00
2014-03-19 19:00:54 +00:00
2012-10-03 02:31:10 +00:00
### In contrast with pythonbrew and pythonz, pyenv _does not..._
2013-08-27 19:27:57 +00:00
* **Depend on Python itself.** pyenv was made from pure shell scripts.
2012-10-03 02:31:10 +00:00
There is no bootstrap problem of Python.
* **Need to be loaded into your shell.** Instead, pyenv's shim
2022-04-03 22:08:49 +00:00
approach works by adding a directory to your `PATH` .
2015-11-28 03:12:54 +00:00
* **Manage virtualenv.** Of course, you can create [virtualenv ](https://pypi.python.org/pypi/virtualenv )
2017-03-06 04:14:12 +00:00
yourself, or [pyenv-virtualenv ](https://github.com/pyenv/pyenv-virtualenv )
2012-10-03 02:31:10 +00:00
to automate the process.
2014-03-20 13:19:11 +00:00
----
2012-08-31 06:23:41 +00:00
## Table of Contents
2014-03-20 13:17:53 +00:00
* **[How It Works](#how-it-works)**
2013-02-06 13:08:16 +00:00
* [Understanding PATH ](#understanding-path )
* [Understanding Shims ](#understanding-shims )
2022-04-03 22:08:49 +00:00
* [Understanding Python version selection ](#understanding-python-version-selection )
* [Locating Pyenv-provided Python Installations ](#locating-pyenv-provided-python-installations )
2014-03-20 13:17:53 +00:00
* **[Installation](#installation)**
2022-04-03 22:08:49 +00:00
* [Getting Pyenv ](#getting-pyenv )
2023-07-23 19:29:17 +00:00
* [UNIX/MacOS ](#unixmacos )
* [Homebrew in macOS ](#homebrew-in-macos )
* [Automatic installer ](#automatic-installer )
* [Basic GitHub Checkout ](#basic-github-checkout )
2022-04-03 22:08:49 +00:00
* [Windows ](#windows )
* [Set up your shell environment for Pyenv ](#set-up-your-shell-environment-for-pyenv )
* [Restart your shell ](#restart-your-shell )
* [Install Python build dependencies ](#install-python-build-dependencies )
* **[Usage](#usage)**
* [Install additional Python versions ](#install-additional-python-versions )
2023-01-21 21:07:53 +00:00
* [Prefix auto-resolution to the latest version ](#prefix-auto-resolution-to-the-latest-version )
2022-06-10 22:14:46 +00:00
* [Python versions with extended support ](#python-versions-with-extended-support )
2022-04-03 22:08:49 +00:00
* [Switch between Python versions ](#switch-between-python-versions )
* [Uninstall Python versions ](#uninstall-python-versions )
* [Other operations ](#other-operations )
* [Upgrading ](#upgrading )
2022-10-30 02:28:53 +00:00
* [Upgrading with Homebrew ](#upgrading-with-homebrew )
* [Upgrading with Installer or Git checkout ](#upgrading-with-installer-or-git-checkout )
2022-04-03 22:08:49 +00:00
* [Uninstalling pyenv ](#uninstalling-pyenv )
2023-04-07 16:06:21 +00:00
* [Pyenv plugins ](#pyenv-plugins )
2022-04-03 22:08:49 +00:00
* [Advanced Configuration ](#advanced-configuration )
* [Using Pyenv without shims ](#using-pyenv-without-shims )
* [Environment variables ](#environment-variables )
2014-03-20 13:17:53 +00:00
* **[Development](#development)**
2022-10-30 02:28:53 +00:00
* [Contributing ](#contributing )
2013-02-06 13:08:16 +00:00
* [Version History ](#version-history )
* [License ](#license )
2014-03-19 19:00:54 +00:00
2014-03-20 13:19:11 +00:00
----
2013-02-06 13:08:16 +00:00
## 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.
2022-04-03 22:08:49 +00:00
2013-02-06 13:08:16 +00:00
### 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` .
2022-04-03 22:08:49 +00:00
2013-02-06 13:08:16 +00:00
### Understanding Shims
pyenv works by inserting a directory of _shims_ at the front of your
`PATH` :
2017-02-06 13:26:13 +00:00
$(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin
2013-02-06 13:08:16 +00:00
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
2022-04-03 22:08:49 +00:00
### Understanding Python version selection
2013-02-06 13:08:16 +00:00
When you execute a shim, pyenv determines which Python version to use by
reading it from the following sources, in this order:
2014-03-19 19:00:54 +00:00
1. The `PYENV_VERSION` environment variable (if specified). You can use
2017-03-06 04:14:12 +00:00
the [`pyenv shell` ](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell ) command to set this environment
2013-02-06 13:08:16 +00:00
variable in your current shell session.
2. The application-specific `.python-version` file in the current
2014-03-19 19:00:54 +00:00
directory (if present). You can modify the current directory's
2017-03-06 04:14:12 +00:00
`.python-version` file with the [`pyenv local` ](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local )
2013-02-06 13:08:16 +00:00
command.
2014-03-19 19:00:54 +00:00
3. The first `.python-version` file found (if any) by searching each parent
directory, until reaching the root of your filesystem.
2013-02-06 13:08:16 +00:00
2017-02-10 01:04:35 +00:00
4. The global `$(pyenv root)/version` file. You can modify this file using
2022-04-03 22:08:49 +00:00
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 (see below).
A special version name "`system`" means to use whatever Python is found on `PATH`
after the shims `PATH` entry (in other words, whatever would be run if Pyenv
shims weren't on `PATH` ). Note that Pyenv considers those installations outside
its control and does not attempt to inspect or distinguish them in any way.
So e.g. if you are on MacOS and have OS-bundled Python 3.8.9 and Homebrew-installed
Python 3.9.12 and 3.10.2 -- for Pyenv, this is still a single "`system`" version,
and whichever of those is first on `PATH` under the executable name you
specified will be run.
2014-03-19 19:00:54 +00:00
2015-06-22 22:54:03 +00:00
**NOTE:** You can activate multiple versions at the same time, including multiple
2015-04-17 22:59:04 +00:00
versions of Python2 or Python3 simultaneously. This allows for parallel usage of
2022-04-03 22:08:49 +00:00
Python2 and Python3, and is required with tools like `tox` . For example, to instruct
Pyenv to first use your system Python and Python3 (which are e.g. 2.7.9 and 3.4.2)
but also have Python 3.3.6, 3.2.1, and 2.5.2 available, you first `pyenv install`
the missing versions, then set `pyenv global system 3.3.6 3.2.1 2.5.2` .
Then you'll be able to invoke any of those versions with an appropriate `pythonX` or
`pythonX.Y` name.
You can also specify multiple versions in a `.python-version` file by hand,
separated by newlines. Lines starting with a `#` are ignored.
[`pyenv which <command>` ](COMMANDS.md#pyenv-which ) displays which real executable would be
run when you invoke `<command>` via a shim.
E.g. if you have 3.3.6, 3.2.1 and 2.5.2 installed of which 3.3.6 and 2.5.2 are selected
and your system Python is 3.2.5,
`pyenv which python2.5` should display `$(pyenv root)/versions/2.5.2/bin/python2.5` ,
`pyenv which python3` -- `$(pyenv root)/versions/3.3.6/bin/python3` and
`pyenv which python3.2` -- path to your system Python due to the fall-through (see below).
Shims also fall through to anything further on `PATH` if the corresponding executable is
not present in any of the selected Python installations.
This allows you to use any programs installed elsewhere on the system as long as
they are not shadowed by a selected Python installation.
### Locating Pyenv-provided Python installations
2013-02-06 13:08:16 +00:00
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
2017-02-06 13:26:13 +00:00
`$(pyenv root)/versions` .
2014-03-19 19:00:54 +00:00
For example, you might have these versions installed:
2013-02-06 13:08:16 +00:00
2017-02-06 13:26:13 +00:00
* `$(pyenv root)/versions/2.7.8/`
* `$(pyenv root)/versions/3.4.2/`
* `$(pyenv root)/versions/pypy-2.4.0/`
2013-02-06 13:08:16 +00:00
2021-05-13 19:57:14 +00:00
As far as Pyenv is concerned, version names are simply directories under
2017-02-06 13:26:13 +00:00
`$(pyenv root)/versions` .
2013-02-06 13:08:16 +00:00
2014-03-20 13:19:11 +00:00
----
2013-02-06 13:08:16 +00:00
## Installation
2022-04-03 22:08:49 +00:00
### Getting Pyenv
2023-07-23 19:29:17 +00:00
#### UNIX/MacOS
##### Homebrew in macOS
2020-05-01 18:07:31 +00:00
2021-05-13 19:57:14 +00:00
1. Consider installing with [Homebrew ](https://brew.sh ):
2020-05-01 18:07:31 +00:00
```sh
2020-05-21 16:29:21 +00:00
brew update
brew install pyenv
2020-05-01 18:07:31 +00:00
```
2024-02-15 19:40:53 +00:00
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
2022-04-03 22:08:49 +00:00
[Set up your shell environment for Pyenv ](#set-up-your-shell-environment-for-pyenv ).
2013-06-13 11:04:37 +00:00
2024-02-15 19:40:53 +00:00
4. OPTIONAL. To fix `brew doctor` 's warning _""config" scripts exist outside your system or Homebrew directories"_
2022-04-03 22:08:49 +00:00
If you're going to build Homebrew formulae from source that link against Python
2021-10-15 19:15:25 +00:00
like Tkinter or NumPy
_(This is only generally the case if you are a developer of such a formula,
2022-04-03 22:08:49 +00:00
or if you have an EOL version of MacOS for which prebuilt bottles are no longer provided
and you are using such a formula)._
2021-10-15 19:15:25 +00:00
To avoid them accidentally linking against a Pyenv-provided Python,
add the following line into your interactive shell's configuration:
2022-04-03 22:08:49 +00:00
2021-10-15 19:15:25 +00:00
* Bash/Zsh:
2022-04-03 22:08:49 +00:00
2021-10-15 19:15:25 +00:00
~~~bash
alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'
~~~
2022-04-03 22:08:49 +00:00
2021-10-15 19:15:25 +00:00
* Fish:
~~~fish
alias brew="env PATH=(string replace (pyenv root)/shims '' \"\$PATH\") brew"
~~~
2014-03-19 19:00:54 +00:00
2022-04-03 22:08:49 +00:00
2023-07-23 19:29:17 +00:00
##### Automatic installer
2014-02-21 03:57:42 +00:00
2023-12-30 15:11:56 +00:00
```bash
curl https://pyenv.run | bash
```
2022-11-29 20:00:22 +00:00
For more details visit our other project:
2017-03-06 04:14:12 +00:00
https://github.com/pyenv/pyenv-installer
2014-02-21 03:57:42 +00:00
2014-03-19 19:00:54 +00:00
2023-07-23 19:29:17 +00:00
##### Basic GitHub Checkout
2012-08-31 06:23:41 +00:00
2021-05-13 19:57:14 +00:00
This will get you going with the latest version of Pyenv and make it
2012-08-31 06:23:41 +00:00
easy to fork and contribute any changes back upstream.
2022-04-03 22:08:49 +00:00
* **Check out Pyenv where you want it installed.**
2021-05-13 19:57:14 +00:00
A good place to choose is `$HOME/.pyenv` (but you can install it somewhere else):
2022-11-28 16:43:11 +00:00
```
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
```
2022-04-03 22:08:49 +00:00
* Optionally, try to compile a dynamic Bash extension to speed up Pyenv. Don't
2021-05-13 19:57:14 +00:00
worry if it fails; Pyenv will still work normally:
2022-11-28 16:43:11 +00:00
```
cd ~/.pyenv & & src/configure & & make -C src
```
2021-05-13 19:57:14 +00:00
2023-07-23 19:29:17 +00:00
#### 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.
2022-04-03 22:08:49 +00:00
### Set up your shell environment for Pyenv
2021-05-13 19:57:14 +00:00
2022-04-03 22:08:49 +00:00
**Upgrade note:** 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.
2021-05-13 19:57:14 +00:00
2022-04-03 22:08:49 +00:00
* 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
2021-05-13 19:57:14 +00:00
2022-05-04 01:28:35 +00:00
The below setup should work for the vast majority of users for common use cases.
2022-05-07 22:16:03 +00:00
See [Advanced configuration ](#advanced-configuration ) for details and more configuration options.
2018-08-28 14:25:51 +00:00
2022-04-03 22:08:49 +00:00
- For **bash** :
2018-08-28 14:25:51 +00:00
2022-05-08 06:46:47 +00:00
Stock Bash startup files vary widely between distributions in which of them source
2022-04-03 22:08:49 +00:00
which, under what circumstances, in what order and what additional configuration they perform.
As such, the most reliable way to get Pyenv in all environments is to append Pyenv
configuration commands to both `.bashrc` (for interactive shells)
and the profile file that Bash would use (for login shells).
2022-08-06 15:12:11 +00:00
First, add the commands to `~/.bashrc` by running the following in your terminal:
2022-04-03 22:08:49 +00:00
~~~ bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
~~~
Then, if you have `~/.profile` , `~/.bash_profile` or `~/.bash_login` , add the commands there as well.
If you have none of these, add them to `~/.profile` .
* to add to `~/.profile` :
~~~ bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.profile
~~~
* to add to `~/.bash_profile` :
~~~ bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
2023-11-12 08:58:17 +00:00
echo '[[ -d $PYENV_ROOT/bin ]] & & export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
2022-04-03 22:08:49 +00:00
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
~~~
- For **Zsh** :
~~~ zsh
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
2023-11-12 08:58:17 +00:00
echo '[[ -d $PYENV_ROOT/bin ]] & & export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
2022-04-03 22:08:49 +00:00
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
~~~
If you wish to get Pyenv in noninteractive login shells as well, also add the commands to `~/.zprofile` or `~/.zlogin` .
- For **Fish shell** :
2022-09-06 18:39:31 +00:00
If you have Fish 3.2.0 or newer, execute this interactively:
~~~ fish
set -Ux PYENV_ROOT $HOME/.pyenv
fish_add_path $PYENV_ROOT/bin
~~~
Otherwise, execute the snippet below:
2022-04-03 22:08:49 +00:00
~~~ fish
set -Ux PYENV_ROOT $HOME/.pyenv
set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths
~~~
2022-09-06 18:39:31 +00:00
Now, add this to `~/.config/fish/config.fish` :
2022-04-03 22:08:49 +00:00
~~~ fish
pyenv init - | source
~~~
**Bash warning** : There are some systems where the `BASH_ENV` variable is configured
to point to `.bashrc` . On such systems, you should almost certainly put the
`eval "$(pyenv init -)"` line into `.bash_profile` , and **not** into `.bashrc` . Otherwise, you
may observe strange behaviour, such as `pyenv` getting into an infinite loop.
See [#264 ](https://github.com/pyenv/pyenv/issues/264 ) for details.
**Proxy note** : If you use a proxy, export `http_proxy` and `https_proxy` , too.
2023-01-05 02:03:45 +00:00
In MacOS, you might also want to install [Fig ](https://fig.io/ ) which
provides alternative shell completions for many command line tools with an
IDE-like popup interface in the terminal window.
(Note that their completions are independent from Pyenv's codebase
so they might be slightly out of sync for bleeding-edge interface changes.)
2022-04-03 22:08:49 +00:00
### Restart your shell
for the `PATH` changes to take effect.
```sh
exec "$SHELL"
```
### Install Python build dependencies
[**Install Python build dependencies** ](https://github.com/pyenv/pyenv/wiki#suggested-build-environment )
before attempting to install a new Python version.
You can now begin using Pyenv.
----
## Usage
### Install additional Python versions
2022-05-08 06:46:47 +00:00
To install additional Python versions, use [`pyenv install` ](COMMANDS.md#pyenv-install ).
2022-04-03 22:08:49 +00:00
For example, to download and install Python 3.10.4, run:
```sh
pyenv install 3.10.4
```
2022-10-30 02:28:53 +00:00
Running `pyenv install -l` gives the list of all available versions.
2022-04-03 22:08:49 +00:00
**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 ](plugins/python-build/README.md#special-environment-variables )
for details.
2023-04-16 17:11:08 +00:00
**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 ).
2023-01-02 22:30:28 +00:00
2022-04-03 22:08:49 +00:00
**NOTE:** If you want to use proxy for download, please set the `http_proxy` and `https_proxy`
environment variables.
2017-05-02 15:52:53 +00:00
2023-04-16 17:11:08 +00:00
**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 ](plugins/python-build/README.md#building-for-maximum-performance ).
2014-09-03 00:51:22 +00:00
2012-08-31 06:23:41 +00:00
2023-01-21 21:07:53 +00:00
#### Prefix auto-resolution to the latest version
2022-10-30 02:28:53 +00:00
2022-11-07 01:46:44 +00:00
All Pyenv subcommands except `uninstall` automatically resolve full prefixes to the latest version in the corresponding version line.
2023-02-28 00:26:18 +00:00
`pyenv install` picks the latest known version, while other subcommands pick the latest installed version.
2022-11-07 01:46:44 +00:00
E.g. to install and then switch to the latest 3.10 release:
2022-10-30 02:28:53 +00:00
```sh
pyenv install 3.10
2022-11-07 01:46:44 +00:00
pyenv global 3.10
2022-10-30 02:28:53 +00:00
```
2023-02-28 00:26:18 +00:00
You can run [`pyenv latest -k <prefix>` ](COMMANDS.md#pyenv-latest ) to see how `pyenv install` would resolve a specific prefix, or [`pyenv latest <prefix>` ](COMMANDS.md#pyenv-latest ) to see how other subcommands would resolve it.
2022-10-30 02:28:53 +00:00
2022-11-07 01:46:44 +00:00
See the [`pyenv latest` documentation ](COMMANDS.md#pyenv-latest ) for details.
2022-10-30 18:38:06 +00:00
2022-10-30 02:28:53 +00:00
2022-06-10 22:14:46 +00:00
#### Python versions with extended support
2022-06-10 22:10:44 +00:00
For the following Python releases, Pyenv applies user-provided patches that add support for some newer environments.
Though we don't actively maintain those patches, since existing releases never change,
it's safe to assume that they will continue working until there are further incompatible changes
2022-06-10 22:14:46 +00:00
in a later version of those environments.
2022-06-10 22:10:44 +00:00
2022-10-30 02:28:53 +00:00
* *3.7.8-3.7.15, 3.8.4-3.8.12, 3.9.0-3.9.7* : XCode 13.3
2023-03-02 08:27:23 +00:00
* *3.5.10, 3.6.15* : MacOS 11+ and XCode 13.3
2022-06-10 22:10:44 +00:00
* *2.7.18* : MacOS 10.15+ and Apple Silicon
2022-04-03 22:08:49 +00:00
### Switch between Python versions
2014-03-19 19:00:54 +00:00
2022-04-03 22:08:49 +00:00
To select a Pyenv-installed Python as the version to use, run one
of the following commands:
* [`pyenv shell <version>` ](COMMANDS.md#pyenv-shell ) -- select just for current shell session
* [`pyenv local <version>` ](COMMANDS.md#pyenv-local ) -- automatically select whenever you are in the current directory (or its subdirectories)
* [`pyenv global <version>` ](COMMANDS.md#pyenv-shell ) -- select globally for your user account
E.g. to select the above-mentioned newly-installed Python 3.10.4 as your preferred version to use:
~~~bash
pyenv global 3.10.4
~~~
Now whenever you invoke `python` , `pip` etc., an executable from the Pyenv-provided
3.10.4 installation will be run instead of the system Python.
Using "`system`" as a version name would reset the selection to your system-provided Python.
See [Understanding shims ](#understanding-shims ) and
[Understanding Python version selection ](#understanding-python-version-selection )
for more details on how the selection works and more information on its usage.
### Uninstall Python versions
As time goes on, you will accumulate Python versions in your
`$(pyenv root)/versions` directory.
2022-08-15 17:25:46 +00:00
To remove old Python versions, use [`pyenv uninstall <versions>` ](COMMANDS.md#pyenv-uninstall ).
2022-04-03 22:08:49 +00:00
Alternatively, you can simply `rm -rf` the directory of the version you want
to remove. You can find the directory of a particular Python version
with the `pyenv prefix` command, e.g. `pyenv prefix 2.6.8` .
Note however that plugins may run additional operations on uninstall
which you would need to do by hand as well. E.g. Pyenv-Virtualenv also
removes any virtual environments linked to the version being uninstalled.
### Other operations
Run `pyenv commands` to get a list of all available subcommands.
Run a subcommand with `--help` to get help on it, or see the [Commands Reference ](COMMANDS.md ).
Note that Pyenv plugins that you install may add their own subcommands.
## Upgrading
2012-08-31 06:23:41 +00:00
2022-10-30 02:28:53 +00:00
### Upgrading with Homebrew
2021-05-13 19:57:14 +00:00
If you've installed Pyenv using Homebrew, upgrade using:
2020-05-01 18:07:31 +00:00
```sh
2020-05-21 16:29:21 +00:00
brew upgrade pyenv
2020-05-01 18:07:31 +00:00
```
2024-02-15 19:40:53 +00:00
To switch from a release to the latest development head of Pyenv, use:
2022-10-30 02:28:53 +00:00
```sh
brew uninstall pyenv
brew install pyenv --head
```
then you can upgrade it with `brew upgrade pyenv` as usual.
### Upgrading with Installer or Git checkout
If you've installed Pyenv with Pyenv-installer, you likely have the
[Pyenv-Update ](https://github.com/pyenv/pyenv-update ) plugin that would
upgrade Pyenv and all installed plugins:
```sh
pyenv update
```
If you've installed Pyenv using Pyenv-installer or Git checkout, you can also
2021-05-13 19:57:14 +00:00
upgrade your installation at any time using Git.
2012-08-31 06:23:41 +00:00
To upgrade to the latest development version of pyenv, use `git pull` :
2017-01-01 10:39:20 +00:00
```sh
2020-05-21 16:29:21 +00:00
cd $(pyenv root)
git pull
2017-01-01 10:39:20 +00:00
```
2012-08-31 06:23:41 +00:00
2021-05-13 19:57:14 +00:00
To upgrade to a specific release of Pyenv, check out the corresponding tag:
2012-08-31 06:23:41 +00:00
2017-01-01 10:39:20 +00:00
```sh
2020-05-21 16:29:21 +00:00
cd $(pyenv root)
git fetch
git tag
git checkout v0.1.0
2017-01-01 10:39:20 +00:00
```
2012-08-31 11:59:24 +00:00
2022-04-03 22:08:49 +00:00
## Uninstalling pyenv
2015-06-09 21:27:21 +00:00
2015-11-21 04:13:52 +00:00
The simplicity of pyenv makes it easy to temporarily disable it, or
2015-06-09 21:27:21 +00:00
uninstall from the system.
2021-05-13 19:57:14 +00:00
1. To **disable** Pyenv managing your Python versions, simply remove the
`pyenv init` invocations from your shell startup configuration. This will
remove Pyenv shims directory from `PATH` , and future invocations like
`python` will execute the system Python version, as it was before Pyenv.
2015-06-09 21:27:21 +00:00
2022-04-03 22:08:49 +00:00
`pyenv` will still be accessible on the command line, but your Python
apps won't be affected by version switching.
2. To completely **uninstall** Pyenv, remove _all_ Pyenv configuration lines
from your shell startup configuration, and then remove
its root directory. This will **delete all Python versions** that were
installed under the `` $(pyenv root)/versions/ `` directory:
2015-06-09 21:27:21 +00:00
2022-04-03 22:08:49 +00:00
```sh
rm -rf $(pyenv root)
```
2021-05-13 19:57:14 +00:00
2022-04-03 22:08:49 +00:00
If you've installed Pyenv using a package manager, as a final step,
perform the Pyenv package removal. For instance, for Homebrew:
2015-06-09 21:27:21 +00:00
2022-04-03 22:08:49 +00:00
```
brew uninstall pyenv
```
2015-06-09 21:27:21 +00:00
2023-04-07 16:06:21 +00:00
## Pyenv plugins
2023-08-29 08:45:11 +00:00
Pyenv provides a simple, flexible and maintainable way to extend and customize its functionality with plugins --
2023-04-07 16:06:21 +00:00
as simple as creating a plugin directory and dropping a shell script on a certain subpath of it
with whatever extra logic you need to be run at certain moments.
See [_Plugins_ on the wiki ](https://github.com/pyenv/pyenv/wiki/Plugins ) on how to install and use plugins
as well as a catalog of some useful existing plugins for common needs.
See [_Authoring plugins_ on the wiki ](https://github.com/pyenv/pyenv/wiki/Authoring-plugins ) on writing your own plugins.
2022-04-03 22:08:49 +00:00
## Advanced Configuration
2012-08-31 11:59:24 +00:00
Skip this section unless you must know what every line in your shell
profile is doing.
2022-04-03 22:08:49 +00:00
Also see the [Environment variables ](#environment-variables ) section
for the environment variables that control Pyenv's behavior.
2012-08-31 11:59:24 +00:00
`pyenv init` is the only command that crosses the line of loading
2021-05-13 19:57:14 +00:00
extra commands into your shell. Coming from RVM, some of you might be
2022-04-03 22:08:49 +00:00
opposed to this idea. Here's what `eval "$(pyenv init -)"` actually does:
2021-09-18 16:03:26 +00:00
2022-04-03 22:08:49 +00:00
1. **Sets up the shims path.** This is what allows Pyenv to intercept
and redirect invocations of `python` , `pip` etc. transparently.
It prepends `$(pyenv root)/shims` to your `$PATH` .
It also deletes any other instances of `$(pyenv root)/shims` on `PATH`
which allows to invoke `eval "$(pyenv init -)"` multiple times without
getting duplicate `PATH` entries.
2021-09-18 16:03:26 +00:00
2022-04-03 22:08:49 +00:00
2. **Installs autocompletion.** This is entirely optional but pretty
useful. Sourcing `$(pyenv root)/completions/pyenv.bash` will set that
up. There are also completions for Zsh and Fish.
2012-08-31 11:59:24 +00:00
2022-04-03 22:08:49 +00:00
3. **Rehashes shims.** From time to time you'll need to rebuild your
shim files. Doing this on init makes sure everything is up to
date. You can always run `pyenv rehash` manually.
2014-03-19 19:00:54 +00:00
2022-04-03 22:08:49 +00:00
4. **Installs `pyenv` into the current shell as a shell function.**
This bit is also optional, but allows
pyenv and plugins to change variables in your current shell.
This is required for some commands like `pyenv shell` to work.
The sh dispatcher doesn't do
anything crazy like override `cd` or hack your shell prompt, but if
for some reason you need `pyenv` to be a real script rather than a
shell function, you can safely skip it.
2012-08-31 06:23:41 +00:00
2022-05-01 22:17:59 +00:00
`eval "$(pyenv init --path)"` only does items 1 and 3.
2013-02-06 13:08:16 +00:00
2022-04-03 22:08:49 +00:00
To see exactly what happens under the hood for yourself, run `pyenv init -`
or `pyenv init --path` .
2013-02-06 13:08:16 +00:00
2022-04-03 22:08:49 +00:00
`eval "$(pyenv init -)"` is supposed to run at any interactive shell's
startup (including nested shells -- e.g. those invoked from editors)
so that you get completion and convenience shell functions.
2013-02-06 13:08:16 +00:00
2022-04-03 22:08:49 +00:00
`eval "$(pyenv init --path)"` can be used instead of `eval "$(pyenv init -)"`
to just enable shims, without shell integration. It can also be used to bump shims
to the front of `PATH` after some other logic has prepended stuff to `PATH`
that may shadow Pyenv's shims.
2014-03-19 19:00:54 +00:00
2022-04-03 22:08:49 +00:00
* In particular, in Debian-based distributions, the stock `~/.profile`
prepends per-user `bin` directories to `PATH` after having sourced `~/.bashrc` .
This necessitates appending a `pyenv init` call to `~/.profile` as well as `~/.bashrc`
in these distributions because the system's Pip places executables for
modules installed by a non-root user into those per-user `bin` directories.
2013-02-06 13:08:16 +00:00
2014-03-20 13:19:11 +00:00
2022-04-03 22:08:49 +00:00
### Using Pyenv without shims
2014-03-20 13:19:11 +00:00
2022-04-03 22:08:49 +00:00
If you don't want to use `pyenv init` and shims, you can still benefit
from pyenv's ability to install Python versions for you. Just run
`pyenv install` and you will find versions installed in
`$(pyenv root)/versions` .
2012-08-31 06:23:41 +00:00
2022-04-03 22:08:49 +00:00
You can manually execute or symlink them as required,
or you can use [`pyenv exec <command>` ](COMMANDS.md#pyenv-exec )
whenever you want `<command>` to be affected by Pyenv's version selection
as currently configured.
2014-03-03 22:11:23 +00:00
2022-04-03 22:08:49 +00:00
`pyenv exec` works by prepending `$(pyenv root)/versions/<selected version>/bin`
to `PATH` in the `<command>` 's environment, the same as what e.g. RVM does.
2012-08-31 11:59:24 +00:00
2014-03-20 13:19:11 +00:00
2022-04-03 22:08:49 +00:00
### Environment variables
2014-03-20 13:19:11 +00:00
2022-05-04 01:28:35 +00:00
You can affect how Pyenv operates with the following environment variables:
2012-08-31 06:23:41 +00:00
2015-03-13 08:14:24 +00:00
name | default | description
-----|---------|------------
2022-05-04 01:28:35 +00:00
`PYENV_VERSION` | | Specifies the Python version to be used.< br > Also see [`pyenv shell` ](COMMANDS.md#pyenv-shell )
2022-04-03 22:08:49 +00:00
`PYENV_ROOT` | `~/.pyenv` | Defines the directory under which Python versions and shims reside.< br > Also see [`pyenv root` ](COMMANDS.md#pyenv-root )
2015-11-21 04:13:52 +00:00
`PYENV_DEBUG` | | Outputs debug information.< br > Also as: `pyenv --debug <subcommand>`
`PYENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for pyenv hooks.
`PYENV_DIR` | `$PWD` | Directory to start searching for `.python-version` files.
2022-04-03 22:08:49 +00:00
`PYTHON_BUILD_ARIA2_OPTS` | | Used to pass additional parameters to [`aria2` ](https://aria2.github.io/ ).< br > If the `aria2c` binary is available on `PATH` , pyenv uses `aria2c` instead of `curl` or `wget` to download the Python Source code. If you have an unstable internet connection, you can use this variable to instruct `aria2` to accelerate the download.< br > In most cases, you will only need to use `-x 10 -k 1M` as value to `PYTHON_BUILD_ARIA2_OPTS` environment variable
2016-12-16 17:08:44 +00:00
2022-06-08 23:52:50 +00:00
See also [_Special environment variables_ in Python-Build's README ](plugins/python-build/README.md#special-environment-variables )
for environment variables that can be used to customize the build.
2022-04-03 22:08:49 +00:00
----
2016-12-16 17:08:44 +00:00
2013-01-04 03:18:05 +00:00
## Development
2012-08-31 06:23:41 +00:00
2015-11-21 04:13:52 +00:00
The pyenv source code is [hosted on
2017-03-06 04:14:12 +00:00
GitHub](https://github.com/pyenv/pyenv). It's clean, modular,
2011-08-11 18:11:37 +00:00
and easy to understand, even if you're not a shell hacker.
2012-08-31 06:23:41 +00:00
2020-04-02 19:24:48 +00:00
Tests are executed using [Bats ](https://github.com/bats-core/bats-core ):
2012-08-31 06:23:41 +00:00
2020-05-21 16:29:21 +00:00
bats test
bats/test/< file > .bats
2012-08-31 06:23:41 +00:00
2022-06-08 23:52:50 +00:00
### Contributing
Feel free to submit pull requests and file bugs on the [issue
2017-03-06 04:14:12 +00:00
tracker](https://github.com/pyenv/pyenv/issues).
2012-08-31 06:23:41 +00:00
2022-06-08 23:52:50 +00:00
See [CONTRIBUTING.md ](CONTRIBUTING.md ) for more details on submitting changes.
2012-08-31 06:23:41 +00:00
2018-03-15 19:42:52 +00:00
### Version History
See [CHANGELOG.md ](CHANGELOG.md ).
2022-06-08 23:52:50 +00:00
2018-03-15 19:42:52 +00:00
### License
[The MIT License ](LICENSE )
2022-04-03 22:08:49 +00:00
[pyenv-virtualenv]: https://github.com/pyenv/pyenv-virtualenv#readme
[hooks]: https://github.com/pyenv/pyenv/wiki/Authoring-plugins#pyenv-hooks