Simple Python version management
The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:
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.
At a high level, pyenv intercepts Python commands using shim executables injected into your
, determines which Python version has been specified by your application, and passes your commands along to the correct Python installation.
When you run a command like
, 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
, with each directory in the list separated by a colon:
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
directory will be searched first, then
pyenv works by inserting a directory of shims at the front of your
Through a process called rehashing, pyenv maintains shims in that directory to match every Python command across every installed version of Python—
, and so on.
Shims are lightweight executables that simply pass your command along to pyenv. So with pyenv installed, when you run, say,
, your operating system will do the following:
for an executable file named
at the beginning of your
, which in turn passes the command along to pyenv
When you execute a shim, pyenv determines which Python version to use by reading it from the following sources, in this order:
environment variable (if specified). You can use the [
](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell) command to set this environment variable in your current shell session. 2.
file in the current directory (if present). You can modify the current directory's
file with the [
file found (if any) by searching each parent directory, until reaching the root of your filesystem. 4.
file. You can modify this file using the [
](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
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
. For example, to set your path to first use your
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
, one would first
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 python2.5
pyenv which python3.4
(should display path to system Python3). You can also specify multiple versions in a
file, separated by newlines or any whitespace.
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
For example, you might have these versions installed:
As far as pyenv is concerned, version names are simply the directories in
There is a pyenv plugin named pyenv-virtualenv which comes with various features to help pyenv users to manage virtual environments created by virtualenv or Anaconda. Because the
script of those virtual environments are relying on mutating
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.
sh brew update brew install pyenv
to your shell to enable shims and autocompletion").
If you're on Windows, consider using @kirankotari's [
](https://github.com/pyenv-win/pyenv-win) fork. (
does not work on windows outside the Windows Subsystem for Linux)
Visit my other project: https://github.com/pyenv/pyenv-installer
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
(but you can install it somewhere else).
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
**Define environment variable
PYENV\_ROOT ```** to point to the path where pyenv repo is cloned and add
for access to the
command-line utility. - For **bash**: ~~~bash echo 'export PYENV_ROOT="$HOME/.pyenv"' \>\> ~/.bash_profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' \>\> ~/.bash_profile~~~ - For **Ubuntu Desktop**: ~~~bash echo 'export PYENV_ROOT="$HOME/.pyenv"' \>\> ~/.bashrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' \>\> ~/.bashrc~~~ - For **Zsh**: ~~~zsh echo 'export PYENV_ROOT="$HOME/.pyenv"' \>\> ~/.zshrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' \>\> ~/.zshrc~~~ - For **Fish shell**: ~~~fish set -Ux PYENV_ROOT $HOME/.pyenv set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths~~~ - **Proxy note**: If you use a proxy, export
too. 1. **Add
to your shell** to enable shims and autocompletion. Please make sure
eval "$(pyenv init -)"
is placed toward the end of the shell configuration file since it manipulates
during the initialization.
sh echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
- **Zsh note**: Modify your
file instead of
. - **fish note**: Use
pyenv init - | source
eval (pyenv init -)
. - **Ubuntu and Fedora note**: Modify your
file instead of
. **General warning**: There are some systems where the
variable is configured to point to
. On such systems you should almost certainly put the above mentioned line
eval "$(pyenv init -)"
, and **not** into
. Otherwise you may observe strange behaviour, such as
getting into an infinite loop. See [#264](https://github.com/pyenv/pyenv/issues/264) for details. 2. **Restart your shell so the path changes take effect.**You can now begin using pyenv.
sh exec "$SHELL"
3. [**Install Python build dependencies**](https://github.com/pyenv/pyenv/wiki#suggested-build-environment) before attempting to install a new Python version. 4. **Install Python versions into
.** For example, to download and install Python 2.7.8, run:
sh pyenv install 2.7.8
**NOTE:** If you need to pass configure option to build, please use
environment variable. **NOTE:** If you want to use proxy to download, please use
environment variable. **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) #### Upgrading If you've installed pyenv using homebrew, upgrade using:
sh brew upgrade pyenv
If you've installed pyenv using the instructions above, you can upgrade your installation at any time using git. To upgrade to the latest development version of pyenv, use
cd $(pyenv root) git pull
To upgrade to a specific release of pyenv, check out the corresponding tag:
cd $(pyenv root) git fetch git tag git checkout v0.1.0
### Uninstalling pyenv The simplicity of pyenv makes it easy to temporarily disable it, or uninstall from the system. 1. To **disable** pyenv managing your Python versions, simply remove the
line from your shell startup configuration. This will remove pyenv shims directory from PATH, and future invocations like
will execute the system Python version, as before pyenv.
will still be accessible on the command line, but your Python apps won't be affected by version switching. 1. To completely **uninstall** pyenv, perform step (1) and then remove its root directory. This will **delete all Python versions** that were installed under
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:
brew uninstall pyenv
### Advanced Configuration Skip this section unless you must know what every line in your shell profile is doing.
is the only command that crosses the line of loading extra commands into your shell. Coming from rvm, some of you might be opposed to this idea. Here's what
actually does: 1. **Sets up your shims path.** This is the only requirement for pyenv to function properly. You can do this by hand by prepending
. 2. **Installs autocompletion.** This is entirely optional but pretty useful. Sourcing
will set that up. There is also a
for Zsh users. 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
manually. 4. **Installs the sh dispatcher.** This bit is also optional, but allows pyenv and plugins to change variables in your current shell, making commands like
possible. The sh dispatcher doesn't do anything crazy like override
or hack your shell prompt, but if for some reason you need
to be a real script rather than a shell function, you can safely skip it. To see exactly what happens under the hood for yourself, run
pyenv init -
. ### Uninstalling Python Versions As time goes on, you will accumulate Python versions in your
directory. To remove old Python versions,
command to automate the removal process. Alternatively, simply
the directory of the version you want to remove. You can find the directory of a particular Python version with the
pyenv prefix 2.6.8
. * * * ## Command Reference See [COMMANDS.md](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md). * * * ## Environment variables You can affect how pyenv operates with the following settings: name | default | description -----|---------|------------
| | Specifies the Python version to be used. Also see [
| Defines the directory under which Python versions and shims reside. Also see
| | Outputs debug information. Also as:
| [_see wiki_](https://github.com/pyenv/pyenv/wiki/Authoring-plugins#pyenv-hooks) | Colon-separated list of paths searched for pyenv hooks.
| Directory to start searching for
| | Used to pass additional parameters to [
](https://aria2.github.io/). If the
binary is available on PATH, pyenv uses
to download the Python Source code. If you have an unstable internet connection, you can use this variable to instruct
to accelerate the download. In most cases, you will only need to use
-x 10 -k 1M
as value to
environment variable ## Development The pyenv source code is [hosted on GitHub](https://github.com/pyenv/pyenv). It's clean, modular, and easy to understand, even if you're not a shell hacker. Tests are executed using [Bats](https://github.com/bats-core/bats-core):
bats test bats/test/.bats
Please feel free to submit pull requests and file bugs on the issue tracker.