2012-08-31 02:23:41 -04:00
# Simple Python Version Management: pyenv
2015-09-20 22:43:40 -04: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 02:23:41 -04: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-27 22:12:54 -05: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 02:23:41 -04:00
2018-02-22 09:43:44 -05:00
![Terminal output example ](/terminal_output.png )
2014-03-19 15:00:54 -04:00
2012-08-31 07:59:24 -04:00
2021-10-23 10:33:18 -04:00
### what pyenv _does..._
2012-08-31 02:23:41 -04:00
2021-10-23 10:33:18 -04: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 02:23:41 -04:00
variable.
2021-10-23 10:33:18 -04:00
* Searches for commands from **multiple versions of Python at a time** .
2015-11-27 22:12:54 -05:00
This may be helpful to test across Python versions with [tox ](https://pypi.python.org/pypi/tox ).
2012-08-31 02:23:41 -04:00
2014-03-19 15:00:54 -04:00
2012-10-02 22:31:10 -04:00
### In contrast with pythonbrew and pythonz, pyenv _does not..._
2013-08-27 15:27:57 -04:00
* **Depend on Python itself.** pyenv was made from pure shell scripts.
2012-10-02 22:31:10 -04:00
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` .
2015-11-27 22:12:54 -05:00
* **Manage virtualenv.** Of course, you can create [virtualenv ](https://pypi.python.org/pypi/virtualenv )
2017-03-05 23:14:12 -05:00
yourself, or [pyenv-virtualenv ](https://github.com/pyenv/pyenv-virtualenv )
2012-10-02 22:31:10 -04:00
to automate the process.
2014-03-19 15:00:54 -04:00
2014-03-20 09:19:11 -04:00
----
2012-08-31 02:23:41 -04:00
## Table of Contents
2014-03-20 09:17:53 -04:00
* **[How It Works](#how-it-works)**
2013-02-06 08:08:16 -05:00
* [Understanding PATH ](#understanding-path )
* [Understanding Shims ](#understanding-shims )
* [Choosing the Python Version ](#choosing-the-python-version )
* [Locating the Python Installation ](#locating-the-python-installation )
2014-03-20 09:17:53 -04:00
* **[Installation](#installation)**
2021-06-08 10:31:54 -04:00
* [Prerequisites ](#prerequisites )
* [Homebrew in macOS ](#homebrew-in-macos )
* [Windows ](#windows )
* [Automatic installer ](#automatic-installer )
2013-02-06 08:08:16 -05:00
* [Basic GitHub Checkout ](#basic-github-checkout )
* [Upgrading ](#upgrading )
2018-10-30 01:02:21 -04:00
* [Homebrew on macOS ](#homebrew-on-macos )
2015-11-17 19:51:03 -05:00
* [Advanced Configuration ](#advanced-configuration )
2013-02-06 08:08:16 -05:00
* [Uninstalling Python Versions ](#uninstalling-python-versions )
2014-03-20 09:17:53 -04:00
* **[Command Reference](#command-reference)**
* **[Development](#development)**
2013-02-06 08:08:16 -05:00
* [Version History ](#version-history )
* [License ](#license )
2014-03-19 15:00:54 -04:00
2014-03-20 09:19:11 -04:00
----
2013-02-06 08:08:16 -05: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.
### 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` :
2017-02-06 08:26:13 -05:00
$(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin
2013-02-06 08:08:16 -05: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
### 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:
2014-03-19 15:00:54 -04:00
1. The `PYENV_VERSION` environment variable (if specified). You can use
2017-03-05 23:14:12 -05:00
the [`pyenv shell` ](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell ) command to set this environment
2013-02-06 08:08:16 -05:00
variable in your current shell session.
2. The application-specific `.python-version` file in the current
2014-03-19 15:00:54 -04:00
directory (if present). You can modify the current directory's
2017-03-05 23:14:12 -05:00
`.python-version` file with the [`pyenv local` ](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local )
2013-02-06 08:08:16 -05:00
command.
2014-03-19 15:00:54 -04: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 08:08:16 -05:00
2017-02-09 20:04:35 -05:00
4. The global `$(pyenv root)/version` file. You can modify this file using
2017-03-05 23:14:12 -05:00
the [`pyenv global` ](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-global ) command. If the global version
2013-02-06 08:08:16 -05:00
file is not present, pyenv assumes you want to use the "system"
2014-03-19 15:00:54 -04:00
Python. (In other words, whatever version would run if pyenv weren't in your
`PATH` .)
2015-06-22 18:54:03 -04:00
**NOTE:** You can activate multiple versions at the same time, including multiple
2015-04-17 18:59:04 -04:00
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`
2017-02-06 08:26:13 -05:00
(should display `$(pyenv root)/versions/2.5/bin/python2.5` ), or `pyenv which
2017-01-02 06:05:36 -05:00
python3.4` (should display path to system Python3). You can also specify multiple
2021-04-13 03:54:42 -04:00
versions in a `.python-version` file, separated by newlines.
2021-04-05 03:22:08 -04:00
Lines starting with a `#` are ignored.
2013-02-06 08:08:16 -05:00
### 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
2017-02-06 08:26:13 -05:00
`$(pyenv root)/versions` .
2014-03-19 15:00:54 -04:00
For example, you might have these versions installed:
2013-02-06 08:08:16 -05:00
2017-02-06 08:26:13 -05:00
* `$(pyenv root)/versions/2.7.8/`
* `$(pyenv root)/versions/3.4.2/`
* `$(pyenv root)/versions/pypy-2.4.0/`
2013-02-06 08:08:16 -05:00
2021-05-13 15:57:14 -04:00
As far as Pyenv is concerned, version names are simply directories under
2017-02-06 08:26:13 -05:00
`$(pyenv root)/versions` .
2013-02-06 08:08:16 -05:00
2016-12-26 19:51:29 -05:00
### Managing Virtual Environments
2017-03-05 23:14:12 -05:00
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.
2016-12-26 19:51:29 -05:00
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.
2014-03-19 15:00:54 -04:00
2014-03-20 09:19:11 -04:00
----
2013-02-06 08:08:16 -05:00
## Installation
2021-06-08 10:31:54 -04:00
### Prerequisites
2020-12-10 19:50:14 -05:00
For pyenv to install python correctly you should [**install the Python build dependencies** ](https://github.com/pyenv/pyenv/wiki#suggested-build-environment ).
2021-06-08 10:31:54 -04:00
### Homebrew in macOS
2020-05-01 14:07:31 -04:00
2021-05-13 15:57:14 -04:00
1. Consider installing with [Homebrew ](https://brew.sh ):
2020-05-01 14:07:31 -04:00
```sh
2020-05-21 12:29:21 -04:00
brew update
brew install pyenv
2020-05-01 14:07:31 -04:00
```
2022-03-18 00:52:26 -04:00
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").
2013-06-13 07:04:37 -04:00
2021-10-15 18:57:05 -04:00
3. OPTIONAL. To fix `brew doctor` 's warning _""config" scripts exist outside your system or Homebrew directories"_
2021-10-15 15:15:25 -04:00
If you're going to build Homebrew formulae from source that link against `libpython`
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 available
and 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"
~~~
2014-03-19 15:00:54 -04:00
2021-06-08 10:31:54 -04: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 run through a compatibility layer --
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.
### Automatic installer
2014-02-20 22:57:42 -05:00
2021-05-13 15:57:14 -04:00
Visit our other project:
2017-03-05 23:14:12 -05:00
https://github.com/pyenv/pyenv-installer
2014-02-20 22:57:42 -05:00
2014-03-19 15:00:54 -04:00
2013-02-06 08:08:16 -05:00
### Basic GitHub Checkout
2012-08-31 02:23:41 -04:00
2021-05-13 15:57:14 -04:00
This will get you going with the latest version of Pyenv and make it
2012-08-31 02:23:41 -04:00
easy to fork and contribute any changes back upstream.
2021-05-13 15:57:14 -04:00
1. **Check out Pyenv where you want it installed.**
A good place to choose is `$HOME/.pyenv` (but you can install it somewhere else):
2012-08-31 02:23:41 -04:00
2020-05-21 12:29:21 -04:00
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
2012-08-31 02:23:41 -04:00
2021-05-13 15:57:14 -04:00
Optionally, try to compile a dynamic Bash extension to speed up Pyenv. Don't
worry if it fails; Pyenv will still work normally:
2020-12-05 11:19:26 -05:00
cd ~/.pyenv & & src/configure & & make -C src
2012-08-31 02:23:41 -04:00
2021-05-13 15:57:14 -04:00
2. **Configure your shell's environment for Pyenv**
2021-06-08 10:23:08 -04:00
**Note:** The below instructions for specific shells are designed for common shell setups;
they also install shell functions into interactive shells only.
2021-09-18 12:03:26 -04:00
If you have an uncommon setup and/or needs and they don't work for you,
use the [Advanced Configuration ](#advanced-configuration )
2021-05-13 15:57:14 -04:00
section below to figure out what you need to do in your specific case.
2021-09-18 12:03:26 -04:00
**General MacOS note:**
2021-10-26 17:26:19 -04:00
[Make sure that your terminal app is configured to run the shell as a login shell ](https://github.com/pyenv/pyenv/wiki/MacOS-login-shell )
2021-09-18 12:03:26 -04:00
(especially if you're using an alternative terminal app and/or shell).
The configuration samples for MacOS are written under this assumption and won't work otherwise.
2021-05-13 15:57:14 -04:00
2021-09-18 12:03:26 -04:00
- For **Bash** :
- **If your `~/.profile` sources `~/.bashrc` (Debian, Ubuntu, Mint):**
~~~bash
# the sed invocation inserts the lines at the start of the file
# after any initial comment lines
2021-09-20 17:30:11 -04:00
sed -Ei -e '/^([^#]|$)/ {a \
2021-09-18 12:03:26 -04:00
export PYENV_ROOT="$HOME/.pyenv"
a \
export PATH="$PYENV_ROOT/bin:$PATH"
a \
' -e ':a' -e '$!{n;ba};}' ~/.profile
echo 'eval "$(pyenv init --path)"' >>~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
~~~
- **If your `~/.bash_profile` sources `~/.bashrc` (Red Hat, Fedora, CentOS):**
2021-05-13 15:57:14 -04:00
~~~ bash
2021-09-20 17:30:11 -04:00
sed -Ei -e '/^([^#]|$)/ {a \
2021-09-18 12:03:26 -04:00
export PYENV_ROOT="$HOME/.pyenv"
a \
export PATH="$PYENV_ROOT/bin:$PATH"
a \
' -e ':a' -e '$!{n;ba};}' ~/.bash_profile
echo 'eval "$(pyenv init --path)"' >> ~/.bash_profile
2021-05-13 15:57:14 -04:00
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init --path)"' >> ~/.profile
2021-09-18 12:03:26 -04:00
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
2021-05-13 15:57:14 -04:00
~~~
2021-09-18 12:03:26 -04:00
- **If you have no `~/.bash_profile` and your `/etc/profile` sources `~/.bashrc` (SUSE):**
~~~bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init --path)"' >> ~/.profile
2021-05-13 15:57:14 -04:00
2021-09-18 12:03:26 -04:00
echo 'if command -v pyenv >/dev/null; then eval "$(pyenv init -)"; fi' >> ~/.bashrc
~~~
2021-06-08 11:10:38 -04:00
2021-09-18 12:03:26 -04:00
- **Otherwise if you have no stock `~/.profile` or `~/.bash_profile` (MacOS):**
~~~bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init --path)"' >> ~/.profile
echo 'if [ -n "$PS1" -a -n "$BASH_VERSION" ]; then source ~/.bashrc; fi' >> ~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
~~~
In MacOS, make sure that your terminal app runs the shell as a login shell.
2021-10-24 18:08:57 -04:00
- **Temporary environments (CI, Docker, batch jobs):**
2021-09-18 12:03:26 -04:00
In CI/build environments, paths and the environment are usually already set up for you
in one of the above ways.
You may only need to install Pyenv as a shell function into the (noninteractive) shell
that runs the batch script, and only if you need subcommands that require `pyenv`
to be a shell function (e.g. `shell` and Pyenv-Virtualenv's `activate` ).
~~~bash
2021-12-07 23:12:53 -05:00
eval "$(pyenv init -)"
2021-09-18 12:03:26 -04:00
~~~
2021-06-01 17:04:26 -04:00
2021-10-24 18:08:57 -04:00
If you are installing Pyenv yourself as part of the batch job,
after installing the files, run the following in the job's shell
to be able to use it.
~~~bash
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH" # if `pyenv` is not already on PATH
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
~~~
2021-09-18 12:03:26 -04:00
**General 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.
- For **Zsh** :
- **MacOS, if Pyenv is installed with Homebrew:**
~~~ zsh
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
~~~
2021-06-01 17:04:26 -04:00
2021-09-18 12:03:26 -04:00
Make sure that your terminal app runs the shell as a login shell.
- **MacOS, if Pyenv is installed with a Git checkout:**
~~~ zsh
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zprofile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zprofile
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
~~~
Make sure that your terminal app runs the shell as a login shell.
2021-06-01 17:04:26 -04:00
2021-09-18 12:03:26 -04:00
- **Other OSes:**
~~~ zsh
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zprofile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zprofile
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
2021-06-01 17:04:26 -04:00
2021-09-18 12:03:26 -04:00
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init --path)"' >> ~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
~~~
2021-05-13 15:57:14 -04:00
2021-10-12 07:09:15 -04:00
- For **Fish shell** :
2021-05-13 15:57:14 -04:00
Execute this interactively:
2021-09-18 12:03:26 -04:00
2021-05-13 15:57:14 -04:00
~~~ fish
set -Ux PYENV_ROOT $HOME/.pyenv
set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths
~~~
And add this to `~/.config/fish/config.fish` :
2021-09-18 12:03:26 -04:00
2021-05-13 15:57:14 -04:00
~~~ fish
2021-09-18 18:08:26 -04:00
status is-login; and pyenv init --path | source
status is-interactive; and pyenv init - | source
2021-05-13 15:57:14 -04:00
~~~
If Fish is not your login shell, also follow the Bash/Zsh instructions to add to `~/.profile` .
**Proxy note** : If you use a proxy, export `http_proxy` and `https_proxy` , too.
2021-09-18 12:03:26 -04:00
4. **Restart your login session for the changes to profile files to take effect.**
2021-05-13 15:57:14 -04:00
E.g. if you're in a GUI session, you need to fully log out and log back in.
2021-05-16 17:46:21 -04:00
2021-09-18 12:03:26 -04:00
In MacOS, restarting terminal windows is enough (because MacOS runs shells
2021-05-16 17:46:21 -04:00
in them as login shells by default).
2018-08-28 10:25:51 -04:00
2020-05-01 14:07:31 -04:00
5. [**Install Python build dependencies** ](https://github.com/pyenv/pyenv/wiki#suggested-build-environment ) before attempting to install a new Python version.
2018-08-28 10:25:51 -04:00
6. **Install Python versions into `$(pyenv root)/versions`.**
2015-11-17 19:35:35 -05:00
For example, to download and install Python 2.7.8, run:
2017-01-01 05:39:20 -05:00
```sh
2020-05-21 12:29:21 -04:00
pyenv install 2.7.8
2017-01-01 05:39:20 -05:00
```
2021-05-13 15:57:14 -04:00
**NOTE:** If you need to pass a `configure` option to a build, please use the
2013-05-16 10:24:21 -04:00
```CONFIGURE_OPTS``` environment variable.
2017-05-02 11:52:53 -04:00
2021-05-13 15:57:14 -04:00
**NOTE:** If you want to use proxy to download, please set the `http_proxy` and `https_proxy`
environment variables.
2014-09-02 20:51:22 -04:00
2021-05-13 15:57:14 -04:00
**NOTE:** If you are having trouble installing a Python version,
2014-09-02 20:51:22 -04:00
please visit the wiki page about
2021-05-13 15:57:14 -04:00
[Common Build Problems ](https://github.com/pyenv/pyenv/wiki/Common-build-problems ).
2012-08-31 02:23:41 -04:00
2014-03-19 15:00:54 -04:00
2013-02-06 08:08:16 -05:00
#### Upgrading
2012-08-31 02:23:41 -04:00
2021-05-13 15:57:14 -04:00
If you've installed Pyenv using Homebrew, upgrade using:
2020-05-01 14:07:31 -04:00
```sh
2020-05-21 12:29:21 -04:00
brew upgrade pyenv
2020-05-01 14:07:31 -04:00
```
2021-05-13 15:57:14 -04:00
If you've installed Pyenv using the instructions above, you can
upgrade your installation at any time using Git.
2012-08-31 02:23:41 -04:00
To upgrade to the latest development version of pyenv, use `git pull` :
2017-01-01 05:39:20 -05:00
```sh
2020-05-21 12:29:21 -04:00
cd $(pyenv root)
git pull
2017-01-01 05:39:20 -05:00
```
2012-08-31 02:23:41 -04:00
2021-05-13 15:57:14 -04:00
To upgrade to a specific release of Pyenv, check out the corresponding tag:
2012-08-31 02:23:41 -04:00
2017-01-01 05:39:20 -05:00
```sh
2020-05-21 12:29:21 -04:00
cd $(pyenv root)
git fetch
git tag
git checkout v0.1.0
2017-01-01 05:39:20 -05:00
```
2012-08-31 07:59:24 -04:00
2015-11-20 23:13:52 -05:00
### Uninstalling pyenv
2015-06-09 17:27:21 -04:00
2015-11-20 23:13:52 -05:00
The simplicity of pyenv makes it easy to temporarily disable it, or
2015-06-09 17:27:21 -04:00
uninstall from the system.
2021-05-13 15:57:14 -04: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 17:27:21 -04:00
2021-05-13 15:57:14 -04:00
`pyenv` will still be accessible on the command line, but your Python
apps won't be affected by version switching.
2015-06-09 17:27:21 -04:00
2021-05-13 15:57:14 -04:00
2. To completely **uninstall** Pyenv, remove _all_ configuration lines for it
from your shell startup configuration, and then remove
2015-11-20 23:13:52 -05:00
its root directory. This will **delete all Python versions** that were
2017-02-06 08:26:13 -05:00
installed under `` $(pyenv root)/versions/ `` directory:
2021-05-13 15:57:14 -04:00
```sh
rm -rf $(pyenv root)
```
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 17:27:21 -04:00
2021-05-13 15:57:14 -04:00
```
brew uninstall pyenv
```
2015-06-09 17:27:21 -04:00
2015-11-17 19:51:03 -05:00
### Advanced Configuration
2012-08-31 07:59:24 -04:00
Skip this section unless you must know what every line in your shell
profile is doing.
`pyenv init` is the only command that crosses the line of loading
2021-05-13 15:57:14 -04:00
extra commands into your shell. Coming from RVM, some of you might be
2021-09-18 12:03:26 -04:00
opposed to this idea.
Also see the [Environment variables ](#environment-variables ) section
for the environment variables that control Pyenv's behavior.
* `eval "$(pyenv init --path)"` :
1. **Sets up your shims path.** This is the only requirement for pyenv to
function properly. You can do this by hand by prepending
`$(pyenv root)/shims` to your `$PATH` .
`eval "$(pyenv init --path)"` is supposed to be run in your session's login
shell startup script -- so that all processes in the session get access to
Pyenv's functionality and it only runs once,
avoiding breaking `PATH` in nested shells
(e.g. shells started from editors/IDEs).
In Linux, GUI managers typically act as a `sh` login shell, running
`/etc/profile` and `~/.profile` at their startup. MacOS' GUI doesn't do that,
so its terminal emulator apps run their shells as login shells by default
to compensate.
* `eval "$(pyenv init -)"` :
1. **Installs autocompletion.** This is entirely optional but pretty
useful. Sourcing `$(pyenv root)/completions/pyenv.bash` will set that
up. There is also a `$(pyenv root)/completions/pyenv.zsh` for Zsh
users.
2. **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.
3. **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, making
commands like `pyenv shell` possible. 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.
`eval "$(pyenv init -)"` is supposed to run at any interactive shell's
startup (including nested shells) so that you get completion and
convenience shell functions.
2012-08-31 07:59:24 -04:00
2021-05-13 15:57:14 -04:00
To see exactly what happens under the hood for yourself, run `pyenv init -`
or `pyenv init --path` .
2014-03-19 15:00:54 -04:00
2021-01-26 01:37:19 -05:00
If you don't want to use `pyenv init` and shims, you can still benefit
2021-05-13 15:57:14 -04:00
from pyenv's ability to install Python versions for you. Just run
`pyenv install` and you will find versions installed in
`$(pyenv root)/versions` , which you can manually execute or symlink
2021-01-26 01:37:19 -05:00
as required.
2012-08-31 02:23:41 -04:00
2013-02-06 08:08:16 -05:00
### Uninstalling Python Versions
2014-03-19 15:00:54 -04:00
As time goes on, you will accumulate Python versions in your
2017-02-06 08:26:13 -05:00
`$(pyenv root)/versions` directory.
2013-02-06 08:08:16 -05:00
To remove old Python versions, `pyenv uninstall` command to automate
the removal process.
2014-09-02 20:51:22 -04:00
Alternatively, simply `rm -rf` the directory of the version you want
to remove. You can find the directory of a particular Python version
2014-03-19 15:00:54 -04:00
with the `pyenv prefix` command, e.g. `pyenv prefix 2.6.8` .
2013-02-06 08:08:16 -05:00
2014-03-20 09:19:11 -04:00
----
2013-02-06 08:08:16 -05:00
## Command Reference
2012-08-31 02:23:41 -04:00
2014-03-20 09:13:15 -04:00
See [COMMANDS.md ](COMMANDS.md ).
2014-03-03 17:11:23 -05:00
2012-08-31 07:59:24 -04:00
2014-03-20 09:19:11 -04:00
----
2015-03-13 04:14:24 -04:00
## Environment variables
2014-03-20 09:19:11 -04:00
2015-11-20 23:13:52 -05:00
You can affect how pyenv operates with the following settings:
2012-08-31 02:23:41 -04:00
2015-03-13 04:14:24 -04:00
name | default | description
-----|---------|------------
2017-05-02 11:52:53 -04:00
`PYENV_VERSION` | | Specifies the Python version to be used.< br > Also see [`pyenv shell` ](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell )
2015-11-20 23:13:52 -05:00
`PYENV_ROOT` | `~/.pyenv` | Defines the directory under which Python versions and shims reside.< br > Also see `pyenv root`
`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.
2019-12-01 20:00:17 -05: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 12:08:44 -05:00
2014-03-19 15:00:54 -04:00
2013-01-03 22:18:05 -05:00
## Development
2012-08-31 02:23:41 -04:00
2015-11-20 23:13:52 -05:00
The pyenv source code is [hosted on
2017-03-05 23:14:12 -05:00
GitHub](https://github.com/pyenv/pyenv). It's clean, modular,
2011-08-11 14:11:37 -04:00
and easy to understand, even if you're not a shell hacker.
2012-08-31 02:23:41 -04:00
2020-04-02 15:24:48 -04:00
Tests are executed using [Bats ](https://github.com/bats-core/bats-core ):
2012-08-31 02:23:41 -04:00
2020-05-21 12:29:21 -04:00
bats test
bats/test/< file > .bats
2012-08-31 02:23:41 -04:00
2011-08-11 14:11:37 -04:00
Please feel free to submit pull requests and file bugs on the [issue
2017-03-05 23:14:12 -05:00
tracker](https://github.com/pyenv/pyenv/issues).
2012-08-31 02:23:41 -04:00
2017-03-05 23:14:12 -05:00
[pyenv-virtualenv]: https://github.com/pyenv/pyenv-virtualenv#readme
[hooks]: https://github.com/pyenv/pyenv/wiki/Authoring-plugins#pyenv-hooks
2018-03-15 15:42:52 -04:00
### Version History
See [CHANGELOG.md ](CHANGELOG.md ).
### License
[The MIT License ](LICENSE )