Did not implement customizable priority due to unclear use feedback and more compilation in the code, can decide and do that separately
Tcl/Tk from MacPorts support is omitted due to CPython's only being compatible with
Tcl/Tk 9 since 3.12.5 and 3.13.0.
Co-authored-by: Ivan Pozdeev <vano@mail.mipt.ru>
1) Got rid of useless call to `cat`, much better to simply use sed with
file as argument.
2) Got rid of `sort -u`. There is no need to sort the list.
Additionally, the list `pyenv.d/rehash/conda.d/default.list` only has
unique entries, and even if you have duplicate entries, the function
will still work. --> No need for sort nor unique.
3) Further improvement is simple, save a cached
cleaned-list-v1.0 in `conda.d` and simple read from that file instead of
doing `sed`, which must be a more expensive operation than simply
reading from file.
Applies to the conda blacklist in `pyenv.d/rehash/conda.d/default.list`
No practical difference, but it looks misplaced when it sits at the end
of the file.
I was doing some debugging with PYENV_DEBUG=1 and noticed that a lot of
work was being done in conda.bash, even though I had not installed any
conda versions like `mambaforge`.
The solution is pretty simple, put all the code inside an if-block.
This aligns with what @varikin found in his pull request #3037
Additionally, I have refactored the code slightly for readability
(created function `build_conda_exclusion_list`), and added comments
which should make it easier to understand what's going on.
This commit simplifies debugging and should reduce the execution time of
```bash
eval "$(pyenv init -)"
```
slightly.
macos_build / macos_build (3.10) (push) Waiting to run
macos_build / macos_build (3.11) (push) Waiting to run
macos_build / macos_build (3.12) (push) Waiting to run
macos_build / macos_build (3.13) (push) Waiting to run
macos_build / macos_build (3.9) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-13) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-14) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-20.04) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-24.04) (push) Waiting to run
ubuntu_build / ubuntu_build (3.10) (push) Waiting to run
ubuntu_build / ubuntu_build (3.11) (push) Waiting to run
ubuntu_build / ubuntu_build (3.12) (push) Waiting to run
ubuntu_build / ubuntu_build (3.13) (push) Waiting to run
ubuntu_build / ubuntu_build (3.9) (push) Waiting to run
Now that ubuntu-24 is out of beta at Github
Since for ubuntu_build, we only use one OS version
and the changes between versions are not as drastic as with MacOS,
it seems safe to have it upgrade automatically.
* perf: replace a series of if statements with a case block. Add error
handling for case where unknown option is provided.
Same setup as rbenv-init for reading arguments.
* perf, docs: Recommend users to specify the shell for `pyenv init -`
Speeds up the startup by about 40% (in local testing, from ~50ms to ~30ms).
Reflect this in `pyenv init` hint text.
* style: remove unnecessary `root` variable in pyenv-init
* style: remove unnecessary variable declarations at the top of file in pyenv-init.
* perf: replace `cat <<` calls with `echo`
The builtin `echo` is about 100x faster. In tests, saves about 2-3ms.
* docs: document the `pyenv init - <shell>` performance boost in the Advanced Configuration section.
* style: test_helper.bash: avoid unnecessary ".." in produced PATH
* docs: fix a false statement about completions location in the Advanced Configuration section.
macos_build / macos_build (3.10) (push) Waiting to run
macos_build / macos_build (3.11) (push) Waiting to run
macos_build / macos_build (3.12) (push) Waiting to run
macos_build / macos_build (3.13) (push) Waiting to run
macos_build / macos_build (3.9) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-13) (push) Waiting to run
pyenv_tests / pyenv_tests (macos-14) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-20.04) (push) Waiting to run
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Waiting to run
ubuntu_build / ubuntu_build (3.10) (push) Waiting to run
ubuntu_build / ubuntu_build (3.11) (push) Waiting to run
ubuntu_build / ubuntu_build (3.12) (push) Waiting to run
ubuntu_build / ubuntu_build (3.13) (push) Waiting to run
ubuntu_build / ubuntu_build (3.9) (push) Waiting to run
Requested in https://github.com/pyenv/pyenv/issues/2680
for deployments with a stock `.pyenv-version` that can use any
of a number of Python versions
and for compatibility with `uv`.
* Support `pyenv local --force`
* Support `pyenv-version-file-write --force`
* Support `pyenv version-name --force`
* Ignore missing versions when searching for executables
* Display "commmand not found" even when there are nonexistent versions
* exec.bats: replace `python` and `rspec` with something that doesn't exist globally, either
in Ubuntu Github CI, `python` exists globally
* Reorganize readme, add gif
1. Details in 'Getting Pyenv' and 'Setup for your shell' are collapsed. User can expand relevant
sections depending on their platform and shell.
2. 'How It Works' and 'Advanced Configuration' are moved to the bottom of the README.md
just before 'Contributing' section at the end.
3. Added a GIF in the 'Usage' section to showcase
- Listing python versions available for install.
- Installing a specific python version.
- Listing installed python versions.
- Switching to another python version for a directory.
- Testing by moving terminal into the directory and moving back.
* Update GIF to show prefix resolution
* Collapse upgrade notes
* Cross-mention Linux and MacOS instlalation scenarios
---------
Co-authored-by: Ivan Pozdeev <vano@mail.mipt.ru>
Since 3.13, CPython is provided in 2 flavors: regular and
free-threaded, with the 't' suffix.
An incomplete prefix ending with '[0-9]t'
resolves only among versions that also end with '[0-9]t'
macos_build / macos_build (3.10) (push) Has been cancelled
macos_build / macos_build (3.11) (push) Has been cancelled
macos_build / macos_build (3.12) (push) Has been cancelled
macos_build / macos_build (3.8) (push) Has been cancelled
macos_build / macos_build (3.9) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-13) (push) Has been cancelled
pyenv_tests / pyenv_tests (macos-14) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-20.04) (push) Has been cancelled
pyenv_tests / pyenv_tests (ubuntu-22.04) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.10) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.11) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.12) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.8) (push) Has been cancelled
ubuntu_build / ubuntu_build (3.9) (push) Has been cancelled
Fixes use of version specifiers like `python-3.12`, which:
- have an explicit `python-` prefix
- are using a major version alias that has to be resolved
to an exact version.
Also simplified the conditional for the already
working case, since it had two branches that were virtually identical.
The directory /usr/etc is an optional directory and used by
Fedora, RHEL 9, and openSUSE. The purpose of /usr/etc is to store
distribution-provided configuration files that can be overridden
by user-modified files in /etc.
/usr/etc is not in FHS. However, as Torsten stated in his comment
(https://github.com/thkukuk/atomic-updates_and_etc/issues/2#issuecomment-524848666)
"[FHS] is currently nearly as dead as LSB, we can only ignore it
if we don't want to stop and kill all innovation."
This PR corrects a small but important detail in the documentation regarding how the system searches for executable files. The original text incorrectly stated that the operating system performs this search. The corrected text clarifies that it is actually the shell that performs the search.
We always detect missing build scripts for `4.13.0-0` because the
release[^1] doesn't have any mambaforge artifacts. Given that we've
already created the build files, we don't need to check the release
again.
[^1]: https://github.com/conda-forge/miniforge/releases/tag/4.13.0-0
The glob pattern we were using was too permissive and detecting
miniconda build scripts as miniforge build scripts when they shared the
same version. I have rewritten the pattern matching code to ensure we
only look at files starting with `miniforge` and `mambaforge`.
In exceptional cases (custom installation, malfunctions elsewhere), `pyenv-commands --sh` may return nothing.
In non-Fish, this would cause "syntax error near unexpected token `)'" in `pyenv()`.
Bash does not allow to specify a `case` option that would never match.
This works around it by defaulting to `/`. Commands, being filenames, can never match it.
In Fish, nothing needs to be done: it apparently does interpret a `case` without argument as one that never matches.
The code for determining which Python version is bundled with which
version of Anaconda has not been updated in a while. I have added 3.10
and 3.11, both of which were used in bundles this year.
I also updated the URL for the source of this data, the Anaconda release
notes, because it has moved.
XCode Command Line Tools 15.0 was recently released, and it contains a
broken version of ncurses 6.0. Some uses of Python's `curses` module
will segfault when compiled with it. The solution is to switch to using
the version of ncurses from Homebrew, which is currently 6.4. Support
for ncurses 6 was added to Python 3.7 and was backported to 3.6 and 2.7,
so this change should not break any recently supported Python versions.
Tested with Python 3.12, 3.11, and 2.7, and all tests in
the `test.test_curses` module pass without issue.
See https://github.com/python/cpython/issues/109617 and
https://github.com/python/cpython/issues/69906 for more information.
It seems that pyenv cannot install 2.7.18 on Mac M1 (Apple ARM).
openssl 1.0.2 does not have ARM support. M1 support was added in 1.1.1i according to
https://www.openssl.org/news/cl111.txt
All include directories should go into CPPFLAGS.
XCode SDK was being added to CFLAGS instead
which caused old Tcl/Tk in the SDK to override a newer one in Homebrew.
According to the POSIX spec, an unescaped backslash not followed by
an escapable character is undefined behavior,
and it has become an error in GNU grep 3.8 (2022-09-02).
The -s flag assures that nothing can be installed to user site-packages
but doesn't keep ensurepip from looking there for Pip.
If Pip is installed in the user site-packages directory, pip won't be installed
for the newly built python -- and its shim won't be created.
-I makes the build install Pip in any case.
The user site-packages installation will override it --
but we'll have the shim at least.
Guthub have recently preinstalled x64 Homebrew OpenSSL to stock MacOS runners. This has caused FreeBSD OpenSSL detection logic to erroneously trigger when running FreeBSD tests in MacOS because their paths happened to coincide.
Replaced checking a specific path with checking with pkg.
Anaconda and miniconda have changed their version string format again,
so the parsing needs to be done differently. `add_miniconda.py` can now
parse all existing definition files properly.
* Support ksh versions
Korn shell had two major versions: ’88 and ’93. Some systems have
ksh installed under the name `ksh93`. A few systems (maybe only
Solaris now) also have a `ksh88`. A few others use the `pdksh` (’88)
or `mksh` (’93) implementations, originated before ksh was open source.
Limit to currently-used versions
---------
Co-authored-by: Kevin Schoedel <kps@datatravelandexperiments.com>
The manpage contains a reference to a file which does
only exist on Debian (/usr/share/pyenv/pyenv_user_setup.bash).
It is replaced by its content to make it usable for
other distributions.
This takes inspiration from the similar script for miniconda, but it
simplifies in a couple of ways:
1. Use the GitHub Releases API instead of scraping HTML.
2. Don't perform a diff, simply add the latest release.
Lots of intermediate miniconda releases have been skipped in the past,
and it doesn't seem particularly valuable to backfill those.
The auto-resolve feature (#2487) means that
pyenv install miniforge3
installs miniforge3-4.10.3-10 and not the exactly named "miniforge3"
recipe. Renaming "miniforge3" to "miniforge3-latest" solves this
issue allowing users to execute
pyenv install miniforge3-latest
This is similar to the naming of the current "miniconda3-latest" recipe.
In some advanced shell setups, the order of custom-added PATH entries is important.
We disregard it by default, always pushing shims to the front of PATH,
to ensure that Pyenv works even in poorly maintained shell environments
and with minimal hassle for non-export users
(an attempt to do the opposite (#1898) has ended in a disaster).
Some advanced users are however ready and able to carefully maintain their environment
and deal with breakages and inconvenience. This option is for them.
* Document listing available versions in the tutorial (#1677)
* Reflect 3.7.15's extended support
* Document using development head with Homebrew
* Structurize the Upgrading section
* Fix Pyenv-latest documentation
For some reason checksum for `Python-3.11.0.tgz` file introduced in
0726e02e3a is invalid. Update that
checksum to ensure `pyenv install 3.11.0` works well on systems without
tar.xz support.
* CI: Bump OS versions
Github released ubuntu-22.04 and macos-12 from beta
and deprecated ubuntu-18.04 and macos-10.15, due to dropping by 2013.
* CI: clean up installed packages
* Don't bother reading empty version files
* Implement version file read in pure bash
Is faster with usual sized version files, slower with degenerate cases.
We're going to eliminate the need to mandatorily use `pyenv init --path`.
We can't delete it yet for backward compatibility.
Besides, there's one other use case for it: to enable shims but without
shell integration, e.g. for noninteractive shells.
To be a full-fledged replacement for `pyenv init -` however,
it needs to do rehashing.
Now the setup is to add to both rc and profile:
1) set PYENV_ROOT
(can do it unconditionally -- since if you change it,
you need to update all places anyway since any of them can be run first)
2) Add `pyenv` to PATH if not already there
3) eval "$(pyenv init -)"
Not a breaking change, old setup will continue to work.
Trace logs without `-v` are usually useless due to missing the build part.
So this leaves one less thing for users to worry about
when submitting error reports.
Mentioning `-v` in the issue template should stay for some time
since users report on old versions, too.
This reverts commit 90d0d20508.
After further consideration, we've decided to remove this workaround:
* It only has an effect if the user has added `gnubin` from Homebrew Coreutils to PATH which is an unsupported setup
* It was intended to be applied only to a few select 3.8 and 3.9 versions that officially support Apple Silicon and only fail with Homebrew Coreutils in PATH because they have `config.*` from a too old version of Autoconf that doesn't support the Arm64 arch -- but
* CPython devs [didn't actually fix the problem in 3.10, either, only in 3.11](https://github.com/pyenv/pyenv/pull/2157#issuecomment-968055387), so we'd need to apply it to all 3.10 releases, too
* users started pushing this workaround into other unrelated branches because they were using the above unsupported setup. See https://github.com/pyenv/pyenv/pull/2190#pullrequestreview-835221952 for discussion.
In my previous work on getting Python 3.6.15 and 3.7.12 to compile on
Apple M1, I backported logic from newer 3.8.x releases to properly find
libffi and related files on macOS.
This regressed compilation on Linux. The include search path was
incomplete, and `ffi.h` could not be found, resulting in `ctypes` being
disabled.
There was a key difference between the old logic and new logic that led
to this regression:
1. In 3.8 and newer, `detect_ctypes()` in `setup.py` took no arguments,
and was expected to access instance variables for the include search
path.
2. In 3.7 and earlier, `detect_ctypes()` took the path as an argument,
and was expected to make use of it.
The backport made use of the instance variables, overriding the provided
include path. These were not equivalent. The one on the instance was not
complete, lacking the necessary directories to find `ffi.h`. Since this
could not be found, `ctypes` support was disabled.
The fix is to simply not overwrite the variables passed to the function,
and resume using them as before.
Fixes#2207
This change ports pyenv and Python patches to 3.7.12 to enable the
`ctypes `and `decimal` modules to compile.
While Python 3.7.12 itself compiles on arm64/M1, both of these modules
fail to compile, due to missing support for locating system libffi and
due to architecture gate-keeping. These issues have been fixed in newer
releases of Python, and in other pyenv patch bundles.
The following patches are provided:
1. `0001-Port-ctypes-and-system-libffi-patches-for-arm64-macO.patch` -
Fixes system `ffi.h`/`libffi` path determination and usage and
enables calling of variadic functions, fixing ctypes support
(consolidated port of existing pyenv patches for 2.7.18 that iterate
on this logic).
2. `0002-bpo-41100-fix-_decimal-for-arm64-Mac-OS-GH-21228.patch` -
Adds arm64 to the list of allowable architectures for the
`decimal` module (port of Python patch introduced in 3.8.10).
This change ports several established patches to the Python 3.6.15
build, enabling compilation on arm64/Apple M1 architectures:
1. `0001-Detect-arm64-in-configure.patch` -
Updates configure to detect arm64 architectures (port of an existing
pyenv patch for 2.7.18).
2. `0002-bpo-36231-Support-building-on-macOS-without-usr-incl.patch` -
Adds macOS SDK root computation logic for determining include paths
(port of existing Python patches introduced in 2.7.17 and 3.7.4).
3. `0003-Fix-macOS-_tkinter-use-of-Tck-Tk-in-Library-Framewor.patch` -
Fixes Tcl/Tk support on macOS (port of an existing pyenv patch
for 2.7.18).
4. `0004-Port-ctypes-and-system-libffi-patches-for-arm64-macO.patch` -
Fixes system `ffi.h`/`libffi` path determination and usage and
enables calling of variadic functions, fixing ctypes support
(consolidated port of existing pyenv patches for 2.7.18 that iterate
on this logic).
5. `0005-BPO-41100-Support-macOS-11-when-building-GH-21113.patch` -
Updates Darwin version checks to handle macOS 11's major version
bump (port of Python patches introduced in 3.7.0 and 3.9.0).
6. `0006-bpo-41100-fix-_decimal-for-arm64-Mac-OS-GH-21228.patch` -
Adds arm64 to the list of allowable architectures for the
`decimal` module (port of Python patch introduced in 3.8.10).
The issue has been resolved in ed38af6409
but the bounty didn't trigger -- allegedly 'cuz it's not a PR.
Bountysource support replied "we're looking" but never did anything
so I'm going to try to trigger it via a dummy PR.
This is needed to find other Python deps (e.g. libintl) in Homebrew if it has
nonstandard prefix (e.g. in Apple M1)
* Re-allow to search Homebrew for zlib everywhere
Link to the active version like other Homebrew deps --
this won't break when another binary-compatible version is installed.
Use a discovery method that doesn't break when other versions are present alongside.
In GNU `sed`, the `-iEe` argument is equivalent to `--in-place=Ee`, which would create `~/.profileEe` as backup of `~/.profile` if the command executed successfully. However, because the `e` is no longer being processed as an expression argument, `sed` does not correctly join the expressions and exits with `sed: -e expression #2, char 10: unexpected }`.
The intent is to use extended regex, perform the changes in-place, and use a series of expressions, so `-Ei -e` is used instead.
This is essentially the same fix as in pull request #2047, but it
is applied from Python 2.6.6 to 2.6.9, and for `ossaudiodev` as well
as the (deprecated) `linuxaudiodev`.
With the normal `setup.py`, the installation of the `ossaudiodev`
module is skipped under GNU/Linux with newer kernel versions because
Python 3.1 appends the major kernel version to the result of
`build_ext.get_platform` and later `ossaudiodev` is skipped if the
major kernel version is not 2. A similar problem might occur if
installing in FreeBSD.
This problem may even occur if installing Python 3.1 in a Docker image
of an old OS (e.g. prehistoric Debian or CentOS), because the major
kernel version is still the one of the host system.
The solution is to use `str.startswith` and only check that the
platform starts with 'linux' or 'freebsd'.
The original 2.3 portable version was compiled on Ubuntu 20.04 and didn't work with older glibc.
This has been fixed and the older file has been deleted so hopefully this change is acceptable.
...rather than login mode.
I couldn't get rid of the warning that `pyenv init -` no longer sets path until I did this. It looks like setting only on the login shell wasn't enough to hide the warning in other shells I opened. This fits with [how rbenv does the same thing](https://github.com/rbenv/rbenv/blob/master/libexec/rbenv-init#L74).
I'm way out of my depth here, so someone who knows about shell types should definitely review this.
Debian/Ubuntu's stock `~/.bashrc` prepends `~/.local/bin` to `PATH` towards its end if it exists.
Executables for per-user modules for system Python are installed into `~/.local/bin` --
so need to prepend `shims` to `PATH` later that that.
Co-authored-by: Ivan Pozdeev <vano@mail.mipt.ru>
Ensuring that all dirs in LDFLAGS exist is only needed for Ruby due to its `configure` requirements.
If some LDFLAGS entries point to a nonexisting path to which the user doesn't have permission. this causes a build failure.
* Update install instructions for Bash and Zsh
* Synchronize README.md with `pyenv init`
* Add a ~/.bash_profile note
* Concatenate shims activation into installation for brevity
(Pyenv can't be used meaningfully without shims anyway)
Otherwise, we'd need to duplicate all the ~/.profile shenanigans in both sections
* Update based on feedback
* Proofread
In certain cases, a user wants to know the cached filename to add the file themselves,
see https://github.com/pyenv/pyenv/issues/1743 .
Since we report both a filename and a URL anyway, there's no reason to report a wrong one.
This behavior is only triggered when the version is provided as an empty string,
is undocumented and breaks if multiple local versions are specified
(rightly so since it's unclear which of them to install).
E.g. for a GUI session, ~/.profile is executed by the GUI login "shell" at its startup
so one needs to fully log out and log back in.
Before that, the change would only be seen by shells explicitly started as login shells.
To support building for Apple ARM64 which was introduced in MacOS 11
OpenSSL added support for Apple ARM in 1.1.1
(61168b5b8d).
Python added support for MacOS 11 in 3.7.8+, 3.8.4+, 3.9.0+
(https://github.com/python/cpython/pull/21113 and backports).
Sometimes it is convenient to be able to temporarily disable something
in a version-file. Because these files often aren't necessarily tracked
in a SCM, especially when working with virtualenvs, the SCM diffs won't
help with showing removed lines which are currently the only way to
disable something.
* Update PyPy download links. Remove releases that are no longer available.
PyPy has moved from bitbucket.org to foss.heptapod.net.
Downloads have moved to https://downloads.python.org/pypy/; some of the archives are no longer available.
Portable PyPy has moved from bitbucket.org to Github. Old archives have been moved to a 3rd-party "Bitbucket Archive" site.
* Update Stackless download links. Remove releases that are no longer available.
Stackless has moved from Bitbucket to Github. Old downloads have been renamed(?); stackless.com no longer works via HTTPS.
* Delete releases that have become invalid since the last check
* fix changed checksums
"hyperfine pyenv-versions" before with my bash 4.4:
Time (mean ± σ): 81.7 ms ± 2.2 ms [User: 67.8 ms, System: 15.7 ms]
Range (min … max): 78.3 ms … 87.2 ms 34 runs
After:
Time (mean ± σ): 70.6 ms ± 2.4 ms [User: 55.6 ms, System: 16.9 ms]
Range (min … max): 67.9 ms … 78.9 ms 41 runs
"hyperfine pyenv-rehash" before on my bash 4.4:
Time (mean ± σ): 172.8 ms ± 8.2 ms [User: 185.0 ms, System: 24.8 ms]
Range (min … max): 164.2 ms … 198.4 ms 15 runs
After:
Time (mean ± σ): 113.8 ms ± 2.8 ms [User: 127.1 ms, System: 26.1 ms]
Range (min … max): 108.0 ms … 117.6 ms 25 runs
OS X arm64 will be installed with Python 3.9 only. Other versions bundled with python 3.8. Miniforge does not have as wide a choice of python versions as miniconda.
The Python version is specific only to the base environment.
... which is caused by `realpath.dylib` containing illegal UTF-8 byte sequence, and `LC_CTYPE` won't take effect if `LC_ALL` happens to be set to something other than `C`.
This commit fixes issue pyenv/pyenv#1454.
Ref: https://stackoverflow.com/a/23584470
PyPy has now only one development tip, `default`,
others are version-line-specific maintenance branches.
The py3k branch has been closed in 2016.
As such, a separate pypy3-dev entry no longer makes sense.
Remove extra whitespace in quoted package_url#checksum string.
Prevent the following error:
unexpected checksum length: 65 (e2562a8d235adc19be5451c170837f53ef916aec4cd5cd17d9e0ab1f1b875d3f )
expected 0 (no checksum), 32 (MD5), or 64 (SHA2-256)
The test "prefix for system in /" is duplicated in test/prefix.bats.
Both tests are completely identical. This commit removes the
duplication.
It appears that the culprit is this merge from rbenv/master, from 2016:
cf1beda362
With the current development version of bats, this leads to the
following error when running `make test`:
Error:
Duplicate test name(s) in file
"/home/travis/build/pyenv/pyenv/test/prefix.bats":
test_prefix_for_system_in_-2f
Note that the development version is what pyenv's Makefile uses. With
the latest release of bats, the duplication only leads to a warning:
bats warning:
duplicate test name(s) in /src/test/prefix.bats:
test_prefix_for_system_in_-2f
* Pin bats to the latest release (1.2.0)
This fixes the following error when running `make test` with bats
installed from its master branch:
/src/bats/libexec/bats-core/bats-exec-file:
line 192:
bats-exec-test:
command not found
The Makefile currently runs bats from its master branch. This can lead
to errors when bats is broken between releases, as is currently the case
with bats at the following commit:
bats-core/bats-core@b615ed8f75
Instead, use the latest release of bats, which is 1.2.0 (2020-04-25).
* Pin bats to latest release on Travis CI
This PR fixes (currently harmless) warning on macOS when homebrew is *not* installed.
- [ ] Test case (required?)
For example:
```sh
wadkar$ pyenv install 3.8.2
/Users/wadkar/.pyenv/plugins/python-build/bin/python-build: line 1541: brew: command not found
/Users/wadkar/.pyenv/plugins/python-build/bin/python-build: line 1541: brew: command not found
Installing openssl-1.1.0j...
Installed openssl-1.1.0j to /Users/wadkar/.pyenv/versions/3.8.2
Installing readline-8.0...
Installed readline-8.0 to /Users/wadkar/.pyenv/versions/3.8.2
Installing Python-3.8.2...
python-build: use zlib from xcode sdk
Installed Python-3.8.2 to /Users/wadkar/.pyenv/versions/3.8.2
```
## before
```Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
local Set or show the local application-specific Python version
global Set or show the global Python version
shell Set or show the shell-specific Python version
install Install a Python version using python-build
uninstall Uninstall a specific Python version
rehash Rehash pyenv shims (run this after installing executables)
version Show the current Python version and its origin
versions List all Python versions available to pyenv
which Display the full path to an executable
whence List all Python versions that contain the given executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
```
## after
```
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
local Set or show the local application-specific Python version
--version Display the version of pyenv
commands List all available pyenv commands
exec Run an executable with the selected Python version
global Set or show the global Python version
help Display help for a command
hooks List hook scripts for a given pyenv command
init Configure the shell environment for pyenv
install Install a Python version using python-build
local Set or show the local application-specific Python version
prefix Display prefix for a Python version
rehash Rehash pyenv shims (run this after installing executables)
root Display the root directory where versions and shims are kept
shell Set or show the shell-specific Python version
shims List existing pyenv shims
uninstall Uninstall a specific Python version
update update pyenv and plugins
version Show the current Python version and its origin
version-file Detect the file that sets the current pyenv version
version-name Show the current Python version
version-origin Explain how the current Python version is set
versions List all Python versions available to pyenv
whence List all Python versions that contain the given executable
which Display the full path to an executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
```
This was imported semi-automatically in 0965577, but `ruby -S` is
different from `python -S`.
`ruby -S`: look for the script using PATH environment variable
`python -S`: don't imply 'import site' on initialization
infocmp is a system utility that returns information about the user's terminal. When it is shimmed it can cause problems for various programs that use it to determine terminal settings. In particular, the library used by the Scala shell reads it and problems can occur where various control keys don't work (e.g. backspace does not work).
previously, it was not possibly to compile a python with homebrew
openssl 1.1 because the code always queried "openssl" and ignored
"openssl@1.1".
now, if 1.1 is installed, it is used to compile python and only
if it is not, 1.0 is checked and used.
All scripts in libexec/ (excluding pyenv) are called through pyenv,
therefore the shebang lines are not necessary. On some systems this
provides a measurable increase in performance of the shell prompt.
Related to pyenv/pyenv-virtualenv#259
The script in `Tools/gdb/libpython.py` has helper functions for
debugging Python processes under gdb. When installed to `{exe}-gdb.py`
it will automatically be loaded by gdb assuming it is in the safe path.
gdb resolves all symlinks, so having the single script is sufficient
regardless of how Python is invoked.
Since it is usually only included as part of a dbg/dev package, this
file is intentionally excluded from install by the CPython build
scripts. Like the packaging with EPEL/Debian, we opt to manually copy
it after the build/install.
To ensure this file gets picked up it is enough for users to put this in
their `~/.gdbinit`:
```
add-auto-load-safe-path ~/.pyenv
```
Fixes#1190.
Command `rbenv version-name > .ruby-version` will create an empty `.ruby-version` file
before running `rbenv-version-file`. This causes `rbenv-version-file` to return empty
string which in turn causes `rbenv-version-name` to return `system`.
Ensure size of `.ruby-version` is non-zero as a workaround.
Shell integration is not enabled by default. This means that, from all the
commands from `rbenv commands`, only "shell" won't work right away.
Replace "no such command" with a more descriptive message that points to
`rbenv init` instead.
* Move Homebrew to the top, common case for new devs
* Note that `brew install rbenv` includes ruby-build by default
* Be clear that `rbenv init` instructions are needed for shell setup
* Be explicit about starting a new shell to pick up PATH/init changes
* Use rbenv-doctor to conclusively demonstrate correct setup
* Separate upgrade instructions for Homebrew vs Git installs
Related: https://github.com/rbenv/ruby-build/pull/1106
This allows subcommand style plugins to properly autocomplete.
Existing commands are not affected.
Example, say you have support for `rbenv foo bar --flag`, then
this allows the last `--flag` argument to be properly completed.
2017-02-10 09:12:30 +01:00
1062 changed files with 32032 additions and 2692 deletions
@@ -17,5 +17,10 @@ Make sure you have checked all steps below.
- [ ] pyenv version:
- [ ] Python version:
- [ ] C Compiler information (e.g. gcc 7.3):
- [ ] Please attach verbose build log as gist
*You can turn on verbose debug logging using by setting `PYENV_DEBUG=1`, e.g. `env PYENV_DEBUG=1 pyenv install -v 3.6.4`
- [ ] Please attach the debug trace of the failing command as a gist:
*Run `env PYENV_DEBUG=1 <faulty command> 2>&1 | tee trace.log` and attach `trace.log`. E.g. if you have a problem with installing Python, run `env PYENV_DEBUG=1 pyenv install -v <version> 2>&1 | tee trace.log` (note the `-v` option to `pyenv install`).
- [ ] If you have a problem with installing Python, please also attach `config.log` from the build directory
* The build directory is reported after the "BUILD FAILED" message and is usually under `/tmp`.
- [ ] If the build succeeds but the problem is still with the build process (e.g. the resulting Python is missing a feature), please attach
* the debug trace from reinstalling the faulty version with `env PYENV_DEBUG=1 pyenv install -f -k -v <version> 2>&1 | tee trace.log`
*`config.log` from the build directory. When using `pyenv install` with `-k` as per above, the build directory will be under `$PYENV_ROOT/sources`.
@@ -3,11 +3,11 @@ Make sure you have checked all steps below.
### Prerequisite
* [ ] Please consider implementing the feature as a hook script or plugin as a first step.
* pyenv has some powerful support for plugins and hook scripts. Please refer to [Authoring plugins](https://github.com/pyenv/pyenv/wiki/Authoring-plugins) for details and try to implement it as a plugin if possible.
* [ ] Please consider contributing the patch upstream to [rbenv](https://github.com/rbenv/rbenv), since we have borrowed most of the code from this project.
* We are occasionally importing the changes from rbenv. In general, you can expect some changes made in rbenv will be imported to pyenv too, eventually.
* Generaly speaking, we sometimes don't prefer to make some change in the core to keep compatibility with rbenv.
* [ ] Please consider contributing the patch upstream to [rbenv](https://github.com/rbenv/rbenv), since we have borrowed most of the code from that project.
* We occasionally import the changes from rbenv. In general, you can expect changes made in rbenv will be imported to pyenv too, eventually.
* Generally speaking, we prefer not to make changes in the core in order to keep compatibility with rbenv.
* [ ] My PR addresses the following pyenv issue (if any)
@@ -16,6 +17,18 @@ The most common subcommands are:
* [`pyenv versions`](#pyenv-versions)
* [`pyenv which`](#pyenv-which)
* [`pyenv whence`](#pyenv-whence)
* [`pyenv exec`](#pyenv-exec)
* [`pyenv root`](#pyenv-root)
* [`pyenv prefix`](#pyenv-prefix)
* [`pyenv latest`](#pyenv-latest)
* [`pyenv hooks`](#pyenv-hooks)
* [`pyenv shims`](#pyenv-shims)
* [`pyenv init`](#pyenv-init)
* [`pyenv completions`](#pyenv-completions)
## `pyenv help`
List all available pyenv commands along with a brief description of what they do. Run `pyenv help <command>` for information on a specific command. For full documentation, see: https://github.com/pyenv/pyenv#readme
## `pyenv commands`
@@ -78,6 +91,10 @@ or, if you prefer 3.3.3 over 2.7.6,
Python 3.3.3
You can use the `-f/--force` flag to force setting versions even if some aren't installed.
This is mainly useful in special cases like provisioning scripts.
## `pyenv global`
Sets the global version of Python to be used in all shells by writing
@@ -216,11 +233,25 @@ Then install the desired versions:
2.6.8
* 2.7.6 (set by /home/yyuu/.pyenv/version)
You can also install the latest version of Python in a specific version line by supplying a prefix instead of a complete name:
$ pyenv install 3.10
See the [`pyenv latest` documentation](#pyenv-latest) for details on prefix resolution.
An older option is to use the `:latest` syntax. For example, to install the latest patch version for Python 3.8 you could do:
pyenv install 3.8:latest
To install the latest major release for Python 3 try:
pyenv install 3:latest
## `pyenv uninstall`
Uninstall a specific Python version.
Uninstall Python versions.
Usage: pyenv uninstall [-f|--force] <version>
Usage: pyenv uninstall [-f|--force] <version> ...
-f Attempt to remove the specified version without prompting
for confirmation. If the version does not exist, do not
@@ -241,8 +272,15 @@ version of Python, or install a package that provides binaries.
Displays the currently active Python version, along with information on
how it was set.
Usage: pyenv version [--bare]
--bare show just the version name. An alias to `pyenv version-name'
$ pyenv version
2.7.6 (set by /home/yyuu/.pyenv/version)
$ pyenv version --bare
2.7.6
## `pyenv versions`
@@ -267,6 +305,8 @@ you run the given command.
$ pyenv which python3.3
/home/yyuu/.pyenv/versions/3.3.3/bin/python3.3
Use --nosystem argument in case when you don't need to search command in the
system environment.
## `pyenv whence`
@@ -276,3 +316,97 @@ Lists all Python versions with the given command installed.
2.6.8
2.7.6
3.3.3
## `pyenv exec`
Usage: pyenv exec <command> [arg1 arg2...]
Runs an executable by first preparing PATH so that the selected Python
version's `bin` directory is at the front.
For example, if the currently selected Python version is 3.9.7:
* The usual principles of respecting existing conventions and making sure that your changes
are in line with the overall product design apply when contributing code to Pyenv.
* We are limited to Bash 3.2 features
That's because that's the version shipped with MacOS.
(They didn't upgrade past it and switched to Zsh because later versions
are covered by GPLv3 which has additional restrictions unacceptable for Apple.)
You can still add performance optimizations etc that take advantage of newer Bash features
as long as there is a fallback execution route for Bash 3.
* Be extra careful when submitting logic specific for the Apple Silicon platform
As of this writing, Github Actions do not support it and only one team member has the necessary hardware.
So we may be unable to test your changes and may have to take your word for it.
Formatting PRs
==============
We strive to keep commit history one-concern-per-commit to keep it meaningful and easy to follow.
If a pull request (PR) addresses a single concern (the typical case), we usually squash commits
from it together when merging so its commit history doesn't matter.
If however a PR addresses multiple separate concerns, each of them should be presented as a separate commit.
Adding multiple new Python releases of the same flavor is okay with either a single or multiple commits.
Authoring installation scripts
==============================
Adding new Python release support
---------------------------------
The easiest way to add support for a new Python release is to copy the script from the previous one
and adjust it as necessary. In many cases, just changing version numbers, URLs and hashes is enough.
Do pay attention to other "magic numbers" that may be present in a script --
e.g. the set of architectures and OS versions supported by a release -- since those change from time to time, too.
Make sure to also copy any patches for the previous release that still apply to the new one.
Typically, a patch no longer applies if it addresses a problem that's already fixed in the new release.
For prereleases, we only create an entry for the latest prerelease in a specific version line.
When submitting a newer prerelease, replace the older one.
Adding version-specific fixes/patches
-------------------------------------
We accept fixes to issues in specific Python releases that prevent users from using them with Pyenv.
In the default configuration for a Python release, we strive to provide as close to vanilla experience as practical,
to maintain [the principle of the least surprise](https://en.wikipedia.org/wiki/Principle_of_least_astonishment).
As such, any such fixes:
* Must not break or degrade (e.g. disable features) the build in any of the environments that the release officially supports
* Must not introduce incompatibilities with the vanilla release (including binary incompatibilities)
* Should not patch things unnecessarily, to minimize the risk of the aforementioned undesirable side effects.
* E.g. if the fix is for a specific environment, its logic ought to only fire in this specific environment and not touch execution paths for other environments.
* As such, it's advisable to briefly explain in the PR what each added patch does and why it is necessary to fix the declared problem
Generally, version-specific fixes belong in the scripts for the affected releases and/or patches for them -- this guarantees that their effect is limited to only those releases.
<h3>Backporting upstream patches</h3>
Usually, this is the easiest way to backport a fix for a problem that is fixed in a newer release.
* Clone Python, check out the tag for the appropriate release and create a branch
* Apply existing patches if there are any (with either `patch` or `git am`) and commit
* Cherry-pick the upstream commit that fixes the problem in a newer release
* Commit and `git format-patch`
* Commit the generated patch file into Pyenv, test your changes and submit a PR
Deprecation policy
------------------
We do not provide official support for EOL releases and environments or otherwise provide any kind of extended support for old Python releases.
We do however accept fixes from interested parties that would allow running older, including EOL, releases in environments that they do not officially support.
In addition to the above requirements for release-specific fixes,
* Such a fix must not add maintenance burden (e.g. add new logic to `python-build` that has to be kept there indefinitely)
* Unless the added logic is useful for both EOL and non-EOL releases. In this case, it will be considered as being primarily an improvement for non-EOL releases.
* Support is provided on a "best effort" basis: we do not actively maintain these fixes but won't actively break them, either, and will accept any corrections.
Since old releases never change, it's pretty safe to assume that the fixes will continue to work until a later version
of an environment introduces further incompatible changes.
Advanced changes / adding new Python flavor support
An installation script is sourced from `python-build`. All installation scripts are based on the same logic:
1. Select the source to download and other variable parameters as needed.
This includes showing an error if the user's environment (OS, architecture) is not supported by the release.
Binary releases that only officially support specific distro(s) typically show a warning in other distros instead.
2. Run one of the `install_*` shell functions
`install_*` shell functions defined in `python-build` install Python from different kinds of sources -- compressed package (binary or source), upstream installation script, VCS checkout. Pick one that's the most appropriate for your packaging.
Each of them accepts a couple of function-specific arguments which are followed by arguments that constitute the build sequence. Each `<argument>` in the build sequence corresponds to the `install_*_<argument>` function in `python-build`. Check what's available and add any functions with logic specific to your flavor if needed.
We strive to keep out of `python-build` parts of build logic that are release-specific and/or tend to change abruptly between releases -- e.g. sets of supported architectures and other software's versions. This results in logic duplication between installation scripts -- but since old releases never change once released, this doesn't really add to the maintenance burden. As a rule of thumb, `python-build` can host parts of logic that are expected to stay the same for an indefinite amount of time -- for an entire Python flavor or release line.
[](https://gitter.im/yyuu/pyenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
**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](plugins/python-build/README.md#building-for-maximum-performance).
</details>
----
#### 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:
```sh
pyenv install 3.10
pyenv global 3.10
```
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.
See the [`pyenv latest` documentation](COMMANDS.md#pyenv-latest) for details.
<details> <summary> Python versions with extended support </summary>
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
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.
----
#### Making multiple versions available
You can select multiple Python versions at the same time by specifying multiple arguments.
E.g. if you wish to use the latest installed CPython 3.11 and 3.12:
~~~bash
pyenv global 3.11 3.12
~~~
Whenever you run a command provided by a Python installation, these versions will be searched for it in the specified order.
[Due to the shims' fall-through behavior]((#understanding-python-version-selection)), `system` is always implicitly searched afterwards.
----
### Uninstall Python versions
As time goes on, you will accumulate Python versions in your
`$(pyenv root)/versions` directory.
To remove old Python versions, use [`pyenv uninstall <versions>`](COMMANDS.md#pyenv-uninstall).
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
### Upgrading with Homebrew
If you've installed Pyenv using Homebrew, upgrade using:
```sh
brew upgrade pyenv
```
To switch from a release to the latest development head of Pyenv, use:
```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
upgrade your installation at any time using Git.
To upgrade to the latest development version of pyenv, use `git pull`:
```sh
cd $(pyenv root)
git pull
```
To upgrade to a specific release of Pyenv, check out the corresponding tag:
```sh
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
`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.
`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:
```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
```
## Pyenv plugins
Pyenv provides a simple way to extend and customize its functionality with plugins --
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.
The main idea is that most things that you can put under `$PYENV_ROOT/<whatever>` you can also put
under `$PYENV_ROOT/plugins/your_plugin_name/<whatever>`.
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.
----
## How It Works
@@ -67,9 +547,10 @@ 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
When you run a command like `python` or `pip`, your shell (bash / zshrc / ...)
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:
@@ -82,6 +563,7 @@ 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
@@ -102,7 +584,8 @@ operating system will do the following:
* Run the shim named `pip`, which in turn passes the command along to
pyenv
### Choosing the Python Version
### Understanding Python version selection
When you execute a shim, pyenv determines which Python version to use by
reading it from the following sources, in this order:
@@ -120,24 +603,45 @@ reading it from the following sources, in this order:
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`.)
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.
**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 or any whitespace.
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.
### Locating the Python Installation
[`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
Once pyenv has determined which version of Python your application has
specified, it passes the command along to the corresponding Python
@@ -152,217 +656,104 @@ For example, you might have these versions installed:
* `$(pyenv root)/versions/3.4.2/`
* `$(pyenv root)/versions/pypy-2.4.0/`
As far as pyenv is concerned, version names are simply the directories in
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
If you're on Mac OS X, consider [installing with Homebrew](#homebrew-on-mac-os-x).
### The automatic installer
Visit my other project:
https://github.com/pyenv/pyenv-installer
### 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.
1.**Check out pyenv where you want it installed.**
A good place to choose is `$HOME/.pyenv` (but you can install it somewhere else).
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 `git pull`:
```sh
$ cd $(pyenv root)
$ git pull
```
To upgrade to a specific release of pyenv, check out the corresponding tag:
```sh
$ cd $(pyenv root)
$ git fetch
$ git tag
v0.1.0
$ 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
`pyenv init` line 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 before pyenv.
`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, perform step (1) and then remove
its root directory. This will **delete all Python versions** that were
installed under `` $(pyenv root)/versions/ `` directory:
```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
### Homebrew on Mac OS X
You can also install pyenv using the [Homebrew](http://brew.sh)
package manager for Mac OS X.
$ brew update
$ brew install pyenv
To upgrade pyenv in the future, use `upgrade` instead of `install`.
Then follow the rest of the post-installation steps under [Basic GitHub Checkout](https://github.com/pyenv/pyenv#basic-github-checkout) above, starting with #3 ("Add `pyenv init` to your shell to enable shims and autocompletion").
### Advanced Configuration
## Advanced Configuration
Skip this section unless you must know what every line in your shell
profile is doing.
Also see the [Environment variables](#environment-variables) section
for the environment variables that control Pyenv's behavior.
`pyenv init` 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 `pyenv init` actually does:
extra commands into your shell. Coming from RVM, some of you might be
opposed to this idea. Here's what `eval "$(pyenv init -)"` 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
`$(pyenv root)/shims` to your `$PATH`.
1. **Finds current shell.**
`pyenv init` figures out what shell you are using, as the exact commands of `eval "$(pyenv init -)"` vary depending on shell. Specifying which shell you are using (e.g. `eval "$(pyenv init - bash)"`) is preferred, because it reduces launch time significantly.
2. **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. **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.
3. **Rehashes shims.** From time to time you'll need to rebuild your
3. **Installs autocompletion.** This is entirely optional but pretty
useful. Sourcing `<pyenvinstallationprefix>/completions/pyenv.bash` will set that
up. There are also completions for Zsh and Fish.
4. **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.
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 `pyenv shell` possible. The sh dispatcher doesn't do
5. **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.
To see exactly what happens under the hood for yourself, run `pyenv init -`.
`eval "$(pyenv init --path)"` only does items 2 and 4.
To see exactly what happens under the hood for yourself, run `pyenv init -`
or `pyenv init --path`.
`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.
`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.
* 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.
### Uninstalling Python Versions
### Using Pyenv without shims
As time goes on, you will accumulate Python versions in your
`$(pyenv root)/versions` directory.
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`.
To remove old Python versions, `pyenv uninstall` command to automate
the removal process.
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.
Alternatively, 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`.
`pyenv exec` works by prepending `$(pyenv root)/versions/<selectedversion>/bin`
to `PATH` in the `<command>`'s environment, the same as what e.g. RVM does.
----
### Environment variables
## Command Reference
See [COMMANDS.md](COMMANDS.md).
----
## Environment variables
You can affect how pyenv operates with the following settings:
You can affect how Pyenv operates with the following environment variables:
name | default | description
-----|---------|------------
`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)
`PYENV_ROOT` | `~/.pyenv` | Defines the directory under which Python versions and shims reside.<br>Also see `pyenv root`
`PYENV_VERSION` | | Specifies the Python version to be used.<br>Also see [`pyenv shell`](COMMANDS.md#pyenv-shell)
`PYENV_ROOT` | `~/.pyenv` | Defines the directory under which Python versions and shims reside.<br>Also see [`pyenv root`](COMMANDS.md#pyenv-root)
`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.
`PYTHON_BUILD_ARIA2_OPTS` | | Used to pass additional parameters to [`aria2`](https://aria2.github.io/).<br>if `aria2c` binary is available on PATH, pyenv use `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
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.
----
## Development
@@ -370,22 +761,29 @@ The pyenv source code is [hosted on
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\.
.P
To start using pyenv
.IP"1."3
\fBAppend\fR the following to \fB$HOME/.bashrc\fR
.P
.RS15
.nf
if command -v pyenv 1>/dev/null 2>&1; then\n
eval "$(pyenv init - bash)" \n
fi
.fi
.RE
.RS3
.P
.nh
Appending this line enables shims. Please make sure this line is placed toward the end of the shell configuration file since it manipulates \fBPATH\fR during the initialization\.
.hy
.TP13
.BDebiannote:
Modify only your \fB~/\.bashrc\fR file instead of creating
.br
\fB~/\.bash_profile\fR
.P
.RS0
\fBZsh note\fR: Modify your \fB~/\.zshrc\fR file instead of \fB~/\.bashrc\fR
.P
\fBWarning\fR: If you configured your system so that \fBBASH_ENV\fR variable points to \fB\.bashrc\fR\. You should almost certainly put the above mentioned line into \fB\.bash_profile\fR, and \fBnot\fR into \fB\.bashrc\fR. Otherwise you may observe strange behaviour, such as \fBpyenv\fR getting into an infinite loop. See #264
.URhttps://github\.com/pyenv/pyenv/issues/264
.UE
for details.
.RE
.RE
.IP"2."3
\fBRestart your shell so the path changes take effect\.\fR You can now begin using pyenv\.
.P
.RS15
exec "$SHELL"\fR
.RE
.IP"3."3
\fBInstall Python versions into \fB$(pyenv root)/versions\fR\.\fR For example, to download and install Python 3\.6\.12, run:
.P
.RS15
.Bpyenvinstall3.6.12\fR
.RE
.P
\fBNOTE:\fR If you need to pass configure option to build, please use \fBCONFIGURE_OPTS\fR environment variable. If you are having trouble installing a python version, please visit the wiki page about Common Build Problems
\fBProxy note\fR: If you use a proxy, export \fBHTTP_PROXY\fR and \fBHTTPS_PROXY\fR environment variables.
.P
.SS"Stop using pyenv"
The simplicity of pyenv makes it easy to temporarily disable it, or uninstall from the system\.
To \fBdisable\fR pyenv managing your Python versions, simply remove the \fBpyenv init\fR line from your shell startup configuration\. This will remove pyenv shims directory from PATH, and future invocations like \fBpython\fR will execute the system Python version, as before pyenv\.
.IP""0
.P
\fBpyenv\fR will still be accessible on the command line, but your Python apps won't be affected by version switching\.
.IP""0
.SHCOMMANDLINEOPTIONS
Like \fBgit\fR, the \fBpyenv\fR command delegates to subcommands based on its first argument\.
.SS"Some useful pyenv commands are:"
.TP5
.Bcommands
List all available pyenv commands
.TP
.Bexec
Run an executable with the selected Python version
.TP
.Bglobal
Set or show the global Python version(s)
.TP
.Bhelp
Display help for a command
.TP
.Bhooks
List hook scripts for a given pyenv command
.TP
.Binit
Configure the shell environment for pyenv
.TP
.Binstall
Install a Python version using python\-build
.TP
.Blocal
Set or show the local application\-specific Python version(s)
.TP
.Bprefix
Display prefix for a Python version
.TP
.Brehash
Rehash pyenv shims (run this after installing executables)
.TP
.Broot
Display the root directory where versions and shims are kept
.TP
.Bshell
Set or show the shell\-specific Python version
.TP
.Bshims
List existing pyenv shims
.TP
.Buninstall
Uninstall Python versions
.TP
.Bversion
Show the current Python version(s) and its origin
.TP
.Bversion\-file
Detect the file that sets the current pyenv version
.TP
.Bversion\-name
Show the current Python version
.TP
.Bversion\-origin
Explain how the current Python version is set
.TP
.Bversions
List all Python versions available to pyenv
.TP
.Bwhence
List all Python versions that contain the given executable
.TP
.Bwhich
Display the full path to an executable
.PP
See `pyenv help <command>' for information on a specific command.
For full documentation, see \fBCOMMAND REFERENCE\fR section
.SHOPTIONS
.TP
.B\-h,\-\-help
Show summary of options.
.TP
.B\-v,\-\-version
Show version of program.
.SHCOMPARISON
.P
.B"pyenvdoes\|\.\|\.\|\.
.P
.IP\(bu4
Let you \fBchange the global Python version\fR on a per\-user basis\.
.IP\(bu4
Provide support for \fBper\-project Python versions\fR\.
.IP\(bu4
Allow you to \fBoverride the Python version\fR with an environment variable\.
.IP\(bu4
Search commands from \fBmultiple versions of Python at a time\fR\. This may be helpful to test across Python versions with tox
.IP""0
.P
.B"In contrast with pythonbrew and pythonz, pyenv does not\|\.\|\.\|\."
.IP\(bu4
\fBDepend on Python itself\.\fR pyenv was made from pure shell scripts\. There is no bootstrap problem of Python\.
.IP\(bu4
\fBNeed to be loaded into your shell\.\fR Instead, pyenv's shim approach works by adding a directory to your \fB$PATH\fR\.
.IP\(bu4
\fBManage virtualenv\.\fR Of course, you can create virtualenv yourself, or pyenv\-virtualenv to automate the process\.
.SH"How It Works"
At a high level, pyenv intercepts Python commands using shim executables injected into your \fBPATH\fR, determines which Python version has been specified by your application, and passes your commands along to the correct Python installation\.
.SS"Understanding PATH"
When you run a command like \fBpython\fR or \fBpip\fR, 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 \fBPATH\fR, with each directory in the list separated by a colon:
.IP""4
.nf
/usr/local/bin:/usr/bin:/bin
.fi
.IP""0
.P
Directories in \fBPATH\fR 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 \fB/usr/local/bin\fR directory will be searched first, then \fB/usr/bin\fR, then \fB/bin\fR\.
.SS"Understanding Shims"
pyenv works by inserting a directory of \fIshims\fR at the front of your \fBPATH\fR:
.IP""4
.nf
$(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin
.fi
.IP""0
.P
Through a process called \fIrehashing\fR, pyenv maintains shims in that directory to match every Python command (\fBpython\fR,\fBpip\fR,etc...) across every installed version of Python
.P
Shims are lightweight executables that simply pass your command along to pyenv\. So with pyenv installed, when you run, say, \fBpip\fR, your operating system will do the following:
.IP\(bu4
Search your \fBPATH\fR for an executable file named \fBpip\fR
.IP\(bu4
Find the pyenv shim named \fBpip\fR at the beginning of your \fBPATH\fR
.IP\(bu4
Run the shim named \fBpip\fR, which in turn passes the command along to pyenv
.IP""0
.SS"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:
.IP"1."4
The \fBPYENV_VERSION\fR environment variable (if specified)\. You can use the \fBpyenv shell\fR command to set this environment variable in your current shell session\.
.IP"2."4
The application\-specific \fB\.python\-version\fR file in the current directory (if present)\. You can modify the current directory's \fB\.python\-version\fR file with the \fBpyenv local\fR command\.
.IP"3."4
The first \fB\.python\-version\fR file found (if any) by searching each parent directory, until reaching the root of your filesystem\.
.IP"4."4
The global \fB$(pyenv root)/version\fR file\. You can modify this file using the \fBpyenv global\fR 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 \fBPATH\fR\.)
.IP""0
.P
.nh
\fBNOTE:\fR 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 \fBtox\fR\. For example, to set your path to first use your \fBsystem\fR 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 \fBPATH\fR, one would first \fBpyenv install\fR the missing versions, then set \fBpyenv global system 3\.3\.6 3\.2 2\.5\fR\. At this point, one should be able to find the full executable path to each of these using \fBpyenv which\fR, e\.g\.\fBpyenv which python2\.5\fR (should display \fB$(pyenv root)/versions/2\.5/bin/python2\.5\fR), or \fBpyenv which python3\.4\fR (should display path to system Python3)\. You can also specify multiple versions in a \fB\.python\-version\fR file, separated by newlines or any whitespace\.
hy
.SS"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\.
.P
Each Python version is installed into its own directory under
.nf
\fB$(pyenv root)/versions\fR\.
.fi
.P
For example, you might have these versions installed:
.IP\(bu4
\fB$(pyenv root)/versions/2\.7\.8/\fR
.IP\(bu4
\fB$(pyenv root)/versions/3\.4\.2/\fR
.IP\(bu4
\fB$(pyenv root)/versions/pypy\-2\.4\.0/\fR
.IP""0
.P
As far as pyenv is concerned, version names are simply the directories in \fB$(pyenv root)/versions\fR\.
.SS"Managing Virtual Environments"
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 \fBactivate\fR script of those virtual environments are relying on mutating \fB$PATH\fR 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"Advanced Configuration"
Skip this section unless you must know what every line in your shell profile is doing\.
.P
\fBpyenv init\fR 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 \fBpyenv init\fR actually does:
.IP"1."4
\fBSets up your shims path\.\fR This is the only requirement for pyenv to function properly\. You can do this by hand by prepending \fB$(pyenv root)/shims\fR to your \fB$PATH\fR\.
.IP"2."4
\fBRehashes shims\.\fR 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 \fBpyenv rehash\fR manually\.
You can disable this functionality by adding \fB--no-rehash\fR to the end of your \fBpyenv init\fR command line.
.IP"3."4
\fBInstalls the sh dispatcher\.\fR This bit is also optional, but allows pyenv and plugins to change variables in your current shell, making commands like \fBpyenv shell\fR possible\. The sh dispatcher doesn't do anything crazy like override \fBcd\fR or hack your shell prompt, but if for some reason you need \fBpyenv\fR to be a real script rather than a shell function, you can safely skip it\.
.IP""0
.P
To see exactly what happens under the hood for yourself, run \fB"pyenv init \-"\fR\.
.SH"Uninstalling Python Versions"
As time goes on, you will accumulate Python versions in your \fB$(pyenv root)/versions\fR directory\.
.P
To remove old Python versions, \fBpyenv uninstall\fR command to automate the removal process\.
.P
Alternatively, simply \fBrm \-rf\fR the directory of the version you want to remove\. You can find the directory of a particular Python version with the \fBpyenv prefix\fR command,
.P
e\.g\.\fBpyenv prefix 2\.6\.8\fR\.
.SH"Command Reference"
.P
The most common subcommands are:
.SS"pyenv commands"
Lists all available pyenv commands\.
.SS"pyenv local"
Sets a local application\-specific Python version by writing the version name to a \fB\.python\-version\fR file in the current directory\. This version overrides the global version, and can be overridden itself by setting the \fBPYENV_VERSION\fR environment variable or with the \fBpyenv shell\fR command\.
.IP""4
.nf
$ pyenv local 2\.7\.6
.fi
.IP""0
.P
When run without a version number, \fBpyenv local\fR reports the currently configured local version\. You can also unset the local version:
.IP""4
.nf
$ pyenv local \-\-unset
.fi
.IP""0
.P
Previous versions of pyenv stored local version specifications in a file named \fB\.pyenv\-version\fR\. For backwards compatibility, pyenv will read a local version specified in an \fB\.pyenv\-version\fR file, but a \fB\.python\-version\fR file in the same directory will take precedence\.
.P
You can specify multiple versions as local Python at once\.
.P
Let's say if you have two versions of 2\.7\.6 and 3\.3\.3\. If you prefer 2\.7\.6 over 3\.3\.3,
.IP""4
.nf
$ pyenv local 2\.7\.6 3\.3\.3
$ pyenv versions
system
* 2\.7\.6 (set by /Users/yyuu/path/to/project/\.python\-version)
* 3\.3\.3 (set by /Users/yyuu/path/to/project/\.python\-version)
$ python \-\-version
Python 2\.7\.6
$ python2\.7 \-\-version
Python 2\.7\.6
$ python3\.3 \-\-version
Python 3\.3\.3
.fi
.IP""0
.P
or, if you prefer 3\.3\.3 over 2\.7\.6,
.IP""4
.nf
$ pyenv local 3\.3\.3 2\.7\.6
$ pyenv versions
system
* 2\.7\.6 (set by /Users/yyuu/path/to/project/\.python\-version)
* 3\.3\.3 (set by /Users/yyuu/path/to/project/\.python\-version)
venv27
$ python \-\-version
Python 3\.3\.3
$ python2\.7 \-\-version
Python 2\.7\.6
$ python3\.3 \-\-version
Python 3\.3\.3
.fi
.IP""0
.SS"pyenv global"
Sets the global version of Python to be used in all shells by writing the version name to the \fB~/\.pyenv/version\fR file\. This version can be overridden by an application\-specific \fB\.python\-version\fR file, or by setting the \fBPYENV_VERSION\fR environment variable\.
.IP""4
.nf
$ pyenv global 2\.7\.6
.fi
.IP""0
.P
The special version name \fBsystem\fR tells pyenv to use the system Python (detected by searching your \fB$PATH\fR)\.
.P
When run without a version number, \fBpyenv global\fR reports the currently configured global version\.
.P
You can specify multiple versions as global Python at once\.
.P
Let's say if you have two versions of 2\.7\.6 and 3\.3\.3\. If you prefer 2\.7\.6 over 3\.3\.3,
.IP""4
.nf
$ pyenv global 2\.7\.6 3\.3\.3
$ pyenv versions
system
* 2\.7\.6 (set by /Users/yyuu/\.pyenv/version)
* 3\.3\.3 (set by /Users/yyuu/\.pyenv/version)
$ python \-\-version
Python 2\.7\.6
$ python2\.7 \-\-version
Python 2\.7\.6
$ python3\.3 \-\-version
Python 3\.3\.3
.fi
.IP""0
.P
or, if you prefer 3\.3\.3 over 2\.7\.6,
.IP""4
.nf
$ pyenv global 3\.3\.3 2\.7\.6
$ pyenv versions
system
* 2\.7\.6 (set by /Users/yyuu/\.pyenv/version)
* 3\.3\.3 (set by /Users/yyuu/\.pyenv/version)
venv27
$ python \-\-version
Python 3\.3\.3
$ python2\.7 \-\-version
Python 2\.7\.6
$ python3\.3 \-\-version
Python 3\.3\.3
.fi
.IP""0
.SS"pyenv shell"
Sets a shell\-specific Python version by setting the \fBPYENV_VERSION\fR environment variable in your shell\. This version overrides application\-specific versions and the global version\.
.IP""4
.nf
$ pyenv shell pypy\-2\.2\.1
.fi
.IP""0
.P
When run without a version number, \fBpyenv shell\fR reports the current value of \fBPYENV_VERSION\fR\. You can also unset the shell version:
.IP""4
.nf
$ pyenv shell \-\-unset
.fi
.IP""0
.P
Note that you'll need pyenv's shell integration enabled (step 3 of the installation instructions) in order to use this command\. If you prefer not to use shell integration, you may simply set the \fBPYENV_VERSION\fR variable yourself:
.IP""4
.nf
$ export PYENV_VERSION=pypy\-2\.2\.1
.fi
.IP""0
.P
You can specify multiple versions via \fBPYENV_VERSION\fR at once\.
.P
Let's say if you have two versions of 2\.7\.6 and 3\.3\.3\. If you prefer 2\.7\.6 over 3\.3\.3,
.IP""4
.nf
$ pyenv shell 2\.7\.6 3\.3\.3
$ pyenv versions
system
* 2\.7\.6 (set by PYENV_VERSION environment variable)
* 3\.3\.3 (set by PYENV_VERSION environment variable)
$ python \-\-version
Python 2\.7\.6
$ python2\.7 \-\-version
Python 2\.7\.6
$ python3\.3 \-\-version
Python 3\.3\.3
.fi
.IP""0
.P
or, if you prefer 3\.3\.3 over 2\.7\.6,
.IP""4
.nf
$ pyenv shell 3\.3\.3 2\.7\.6
$ pyenv versions
system
* 2\.7\.6 (set by PYENV_VERSION environment variable)
* 3\.3\.3 (set by PYENV_VERSION environment variable)
venv27
$ python \-\-version
Python 3\.3\.3
$ python2\.7 \-\-version
Python 2\.7\.6
$ python3\.3 \-\-version
Python 3\.3\.3
.fi
.IP""0
.SS"pyenv install"
Install a Python version
.IP""4
.nf
Usage: pyenv install [\-f] [\-kvp] <version>
pyenv install [\-f] [\-kvp] <definition\-file>
pyenv install \-l|\-\-list
\-l, \-\-list List all available versions
\-f, \-\-force Install even if the version appears to be installed
already
\-s, \-\-skip\-existing Skip the installation if the version appears to be
installed already
python\-build options:
\-k, \-\-keep Keep source tree in $PYENV_BUILD_ROOT after installation
(defaults to $PYENV_ROOT/sources)
\-v, \-\-verbose Verbose mode: print compilation status to stdout
\-p, \-\-patch Apply a patch from stdin before building
\-g, \-\-debug Build a debug version
.fi
.IP""0
.P
To list the all available versions of Python, including Anaconda, Jython, pypy, and stackless, use:
\-f Attempt to remove the specified version without prompting
for confirmation\. If the version does not exist, do not
display an error message\.
.fi
.IP""0
.SS"pyenv rehash"
Installs shims for all Python binaries known to pyenv (i\.e\., \fB~/\.pyenv/versions/*/bin/*\fR)\. Run this command after you install a new version of Python, or install a package that provides binaries\.
.IP""4
.nf
$ pyenv rehash
.fi
.IP""0
.SS"pyenv version"
Displays the currently active Python version, along with information on how it was set\.
.IP""4
.nf
$ pyenv version
2\.7\.6 (set by /home/yyuu/\.pyenv/version)
.fi
.IP""0
.SS"pyenv versions"
Lists all Python versions known to pyenv, and shows an asterisk next to the currently active version\.
.IP""4
.nf
$ pyenv versions
2\.5\.6
2\.6\.8
* 2\.7\.6 (set by /home/yyuu/\.pyenv/version)
3\.3\.3
jython\-2\.5\.3
pypy\-2\.2\.1
.fi
.IP""0
.SS"pyenv which"
Displays the full path to the executable that pyenv will invoke when you run the given command\.
Lists all Python versions with the given command installed\.
.IP""4
.nf
$ pyenv whence 2to3
2\.6\.8
2\.7\.6
3\.3\.3
.fi
.IP""0
.SH"Environment variables"
You can affect how pyenv operates with the following settings:
.TP28
.Bname(default)
.Bdescription
.TP28
.BPYENV_VERSION
Specifies the Python version to be used. Also see \fBpyenv shell\fR
.TP
.BPYENV_ROOT(\fB~/.pyenv\fR)
Defines the directory under which Python versions and shims reside. Also see \fBpyenv root\fR
.TP
.BPYENV_DEBUG
Outputs debug information.
.br
Also as: \fBpyenv --debug <subcommand>\fR
.TP
.BPYENV_HOOK_PATH
Colon\-separated list of paths searched for pyenv hooks\.
.TP
.BPYENV_DIR(\fB$PWD\fR)
Directory to start searching for \fB\.python\-version\fR files\.
.TP
.BHTTP_PROXY,HTTPS_PROXY
Proxy Variables
.TP
.BCONFIGURE_OPTS
Pass configure options to build.
.TP
.BPYTHON_BUILD_ARIA2_OPTS
Used to pass additional parameters to \fBaria2\fR
.URhttps://aria2\.github\.io/
.UE
If the \fBaria2c\fR binary is available on PATH, pyenv uses \fBaria2c\fR instead of \fBcurl\fR or \fBwget\fR to download the Python Source code\. If you have an unstable internet connection, you can use this variable to instruct \fBaria2\fR to accelerate the download\.
In most cases, you will only need to use \fB\-x 10 \-k 1M\fR as value to \fBPYTHON_BUILD_ARIA2_OPTS\fR environment variable
You need nothing to do since python-build is bundled with pyenv by
default.
Since python-build is bundled with pyenv by
default, you do not need to do anything.
### Installing as a standalone program (advanced)
@@ -24,7 +24,7 @@ Installing python-build as a standalone program will give you access to the
`python-build` command for precise control over Python version installation. If you
have pyenv installed, you will also be able to use the `pyenv install` command.
git clone git://github.com/pyenv/pyenv.git
git clone https://github.com/pyenv/pyenv.git
cd pyenv/plugins/python-build
./install.sh
@@ -96,7 +96,64 @@ versions of Python that are not yet supported by python-build.
See the [python-build built-in definitions](https://github.com/pyenv/pyenv/tree/master/plugins/python-build/share/python-build) as a starting point for
Without the user customizing the build with environment variables (see below),
`python-build` builds Python with mostly default Configure options
to maintain the principle of the least surprise.
The exceptions -- non-default options that are set by default -- are listed below:
| Option/Behavior | Rationale |
|-----------------|-----------|
| `--enable-shared` is on by default. Pass `--disable-shared` to Configure options to override | The official CPython Docker image uses it. It's required to embed CPython. |
| argument to `--enable-universalsdk` is ignored and set to `/` |
| `--with-universal-archs` defaults to `universal2` on ARM64 architecture | the only dual-architecture Macs in use today are Apple Silicon which can only build that one |
| argument to `--enable-framework` is ignored and set to a specific value | CPython's build logic requires a very specific argument to avoid installing the `Applications` part globally |
| argument to `--enable-unicode` in non-MacOS is overridden to `ucs4` for 2.x-3.3 |
| `MACOSX_DEPLOYMENT_TARGET` defaults to the running MacOS version |
#### Integration with 3rd-party package ecosystems
##### Homebrew
Homebrew is used to find dependency packages if `brew` is found on `PATH`:
* In MacOS, or
* If the running Pyenv itself is installed with Homebrew
Set `PYTHON_BUILD_USE_HOMEBREW` or `PYTHON_BUILD_SKIP_HOMEBREW` to override this default.
When Homebrew is used, its `include` and `lib` paths are added to compiler search path (the latter is also set as `rpath`),
and also Python dependencies that are typically keg-only are searched for in the Homebrew installation and added individually.
**NOTE:** Homebrew is not used in Linux by default because it's rolling-release which causes a problem.
Upgrading a Python dependency in Homebrew to a new major version (that `brew` does without warning)
would break all Pyenv-managed installations that depend on it.
You can use a [community plugin `fix-version`](https://github.com/pyenv/pyenv/wiki/Plugins#community-plugins)
to fix installations in such a case.
##### MacPorts
MacPorts Homebrew is used to find dependency packages if `port` is found on `PATH` in MacOS.
Set `PYTHON_BUILD_USE_MACPORTS` or `PYTHON_BUILD_SKIP_MACPORTS` to override this default.
###### Interaction with Homebrew
If both Homebrew and MacPorts are installed and allowed to be used, Homebrew takes preference.
There first ecosystem where any of the required dependency packages is found is used.
##### Portage
In FreeBSD, if `pkg` is on PATH, Ports are searched for some dependencies that Configure is known to not search for via `pkg-config`.
(Later versions of CPython search for more packages via `pkg-config` so this may eventually become redundant.)
### Special environment variables
@@ -109,23 +166,30 @@ You can set certain environment variables to control the build process.
downloaded package files.
*`PYTHON_BUILD_MIRROR_URL` overrides the default mirror URL root to one of your
choosing.
*`PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM`, if set, does not append the SHA2
checksum of the file to the mirror URL.
*`PYTHON_BUILD_SKIP_MIRROR`, if set, forces python-build to download packages from
their original source URLs instead of using a mirror.
*`PYTHON_BUILD_HTTP_CLIENT`, explicitly specify the HTTP client type to use. `aria2`, `curl` and `wget` are the supported values and by default, are searched in that order.
*`PYTHON_BUILD_CURL_OPTS`, `PYTHON_BUILD_WGET_OPTS`, `PYTHON_BUILD_ARIA2_OPTS` pass additional parameters to the corresponding HTTP client.
*`PYTHON_BUILD_SKIP_HOMEBREW`, if set, will not search for libraries installed by Homebrew when it would normally will.
*`PYTHON_BUILD_USE_HOMEBREW`, if set, will search for libraries installed by Homebrew when it would normally not.
*`PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA`, override the Homebrew OpenSSL formula to use.
*`PYTHON_BUILD_SKIP_MACPORTS`, if set, will not search for libraries installed by MacPorts when it would normally will.
*`PYTHON_BUILD_USE_MACPORTS`, if set, will search for libraries installed by MacPorts when it would normally not.
*`PYTHON_BUILD_ROOT` overrides the default location from where build definitions
in `share/python-build/` are looked up.
*`PYTHON_BUILD_DEFINITIONS` can be a list of colon-separated paths that get
additionally searched when looking up build definitions.
*`CC` sets the path to the C compiler.
*`PYTHON_CFLAGS` lets you pass additional options to the default `CFLAGS`. Use
this to override, for instance, the `-O3` option.
*`CONFIGURE_OPTS` lets you pass additional options to `./configure`.
*`MAKE` lets you override the command to use for `make`. Useful for specifying
GNU make (`gmake`) on some systems.
*`MAKE_OPTS` (or `MAKEOPTS`) lets you pass additional options to `make`.
*`MAKE_INSTALL_OPTS` lets you pass additional options to `make install`.
*`PYTHON_CONFIGURE_OPTS` and `PYTHON_MAKE_OPTS` and `PYTHON_MAKE_INSTALL_OPTS` allow
you to specify configure and make options for building CPython. These variables
will be passed to Python only, not any dependent packages (e.g. libyaml).
*`<PACKAGE>_CFLAGS`, `<PACKAGE>_CPPFLAGS`, `<PACKAGE>_LDFLAGS` let you pass additional options to `CFLAGS`/`CPPFLAGS`/`LDFLAGS` specifically for building `<package>` (Python itself or a dependency library) from source as part of the build script. `<PACKAGE>` should be a capitalized name of the package without version (technically, capitalized first argument to `install_package` without version). E.g. for CPython, it's "`PYTHON`", for Readline, "`READLINE`", for PyPy (only applies when building it from source), "`PYPY`". Check the source of the build script you're using if unsure.
you to specify configure and make options for building `<package>` (same as above). "Make install target" would replace "`install`" in the `make install` invocation.
install_package "Python-2.1.3" "https://www.python.org/ftp/python/2.1.3/Python-2.1.3.tgz#1bcb5bb587948bc38f36db60e15c376009c56c66570e563a08a82bf7f227afb9" standard verify_py21
install_package "Python-2.2.3" "https://www.python.org/ftp/python/2.2.3/Python-2.2.3.tgz#a8f92e6b89d47359fff0d1fbfe47f104afc77fd1cd5143e7332758b7bc100188" standard verify_py22
install_package "Python-2.3.7" "https://www.python.org/ftp/python/2.3.7/Python-2.3.7.tgz#969a9891dce9f50b13e54f9890acaf2be66715a5895bf9b11111f320c205b90e" standard verify_py23
install_package "Python-2.4" "https://www.python.org/ftp/python/2.4/Python-2.4.tgz#ff746de0fae8691c082414b42a2bb172da8797e6e8ff66c9a39d2e452f7034e9" standard verify_py24
install_package "Python-2.4.1" "https://www.python.org/ftp/python/2.4.1/Python-2.4.1.tgz#f449c3b167389324c525ad99d02376c518ac11e163dbbbc13bc88a5c7101fd00" standard verify_py24
install_package "Python-2.4.2" "https://www.python.org/ftp/python/2.4.2/Python-2.4.2.tgz#2653e1846e87fd9b3ee287fefc965c80c54646548b4913a22265b0dd54493adf" standard verify_py24
install_package "Python-2.4.3" "https://www.python.org/ftp/python/2.4.3/Python-2.4.3.tgz#985a413932f5e31e6280b37da6b285a3a0b2748c6786643989ed9b23de97e2d5" standard verify_py24
install_package "Python-2.4.4" "https://www.python.org/ftp/python/2.4.4/Python-2.4.4.tgz#92be6e20cbc3111d9dd0c016d72ef7914c23b879dc52df7ba28df97afbf12e2e" standard verify_py24
install_package "Python-2.4.5" "https://www.python.org/ftp/python/2.4.5/Python-2.4.5.tgz#6ae6f67a388a7f70ed3a20eebab5aae995ee433089d1f1724095c62f4b7389a1" standard verify_py24
install_package "Python-2.4.6" "https://www.python.org/ftp/python/2.4.6/Python-2.4.6.tgz#b03f269e826927f05c966cf4f4414f3c93ee2314960859e7f8375e24e82f8b02" standard verify_py24
install_package "Python-2.5" "https://www.python.org/ftp/python/2.5/Python-2.5.tgz#d7bbf42e36003c6065cd19f3e67d283521858515ee923220f654131cebe1d8f2" standard verify_py25
install_package "Python-2.5.1" "https://www.python.org/ftp/python/2.5.1/Python-2.5.1.tgz#1f5caee846049ca30d996f9403eefdb996295c4af664867e35dcc5eb36e4e7e8" standard verify_py25
install_package "Python-2.5.2" "https://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz#834afe8a88adaf623b05ac5dd6700dd5bb5d0d5553fc74ad529359a3496e4ae3" standard verify_py25
install_package "Python-2.5.3" "https://www.python.org/ftp/python/2.5.3/Python-2.5.3.tgz#c3fee607d20a77dfb72ea2e627eb4d95d25c735603435abde62c57015a0445bd" standard verify_py25
install_package "Python-2.5.4" "https://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz#3d3b205611ee503a38a9433d5645a571668420bb219242c7f51af85f05664da6" standard verify_py25
install_package "Python-2.5.5" "https://www.python.org/ftp/python/2.5.5/Python-2.5.5.tgz#03be1019c4fe93daeb53ba9e4294bf22a8ed4cb854cbd57e24e16f6bf63e2392" standard verify_py25
install_package "Python-2.5.6" "https://www.python.org/ftp/python/2.5.6/Python-2.5.6.tgz#c2e4377597241b1065677d23327c04d0f41945d370c61a491cc88be367234c5d" standard verify_py25
install_package "Python-2.7.6" "https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz#99c6860b70977befa1590029fae092ddb18db1d69ae67e8b9385b66ed104ba58" standard verify_py27 copy_python_gdb ensurepip
Some files were not shown because too many files have changed in this diff
Show More
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.