Update install instructions for Bash and Zsh (#1920)

* 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
This commit is contained in:
native-api 2021-05-13 22:57:14 +03:00 committed by GitHub
parent a7f3e3a5be
commit 0d07cda969
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 172 additions and 101 deletions

221
README.md
View file

@ -153,7 +153,7 @@ For example, you might have these versions installed:
* `$(pyenv root)/versions/3.4.2/` * `$(pyenv root)/versions/3.4.2/`
* `$(pyenv root)/versions/pypy-2.4.0/` * `$(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`. `$(pyenv root)/versions`.
### Managing Virtual Environments ### Managing Virtual Environments
@ -174,95 +174,137 @@ For pyenv to install python correctly you should [**install the Python build dep
### Homebrew on macOS ### Homebrew on macOS
1. Consider installing with [Homebrew](https://brew.sh) 1. Consider installing with [Homebrew](https://brew.sh):
```sh ```sh
brew update brew update
brew install pyenv brew install pyenv
``` ```
2. Then follow the rest of the post-installation steps under [Basic GitHub Checkout](https://github.com/pyenv/pyenv#basic-github-checkout), starting with #3 ("Add `pyenv init` to your shell to enable shims and autocompletion"). 2. Then follow the rest of the post-installation steps under [Basic GitHub Checkout](https://github.com/pyenv/pyenv#basic-github-checkout), starting with #2 ("Configure your shell's environment for Pyenv").
If you're on Windows, consider using @kirankotari's [`pyenv-win`](https://github.com/pyenv-win/pyenv-win) fork. (`pyenv` does not work on windows outside the Windows Subsystem for Linux) If you're on Windows, consider using @kirankotari's [`pyenv-win`](https://github.com/pyenv-win/pyenv-win) fork. (Pyenv does not work in Windows outside the Windows Subsystem for Linux.)
### The automatic installer ### The automatic installer
Visit my other project: Visit our other project:
https://github.com/pyenv/pyenv-installer https://github.com/pyenv/pyenv-installer
### Basic GitHub Checkout ### Basic GitHub Checkout
This will get you going with the latest version of pyenv and make it This will get you going with the latest version of Pyenv and make it
easy to fork and contribute any changes back upstream. easy to fork and contribute any changes back upstream.
1. **Check out pyenv where you want it installed.** 1. **Check out Pyenv where you want it installed.**
A good place to choose is `$HOME/.pyenv` (but you can install it somewhere else). A good place to choose is `$HOME/.pyenv` (but you can install it somewhere else):
git clone https://github.com/pyenv/pyenv.git ~/.pyenv git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Optionally, try to compile dynamic bash extension to speed up pyenv. Don't Optionally, try to compile a dynamic Bash extension to speed up Pyenv. Don't
worry if it fails; pyenv will still work normally: worry if it fails; Pyenv will still work normally:
cd ~/.pyenv && src/configure && make -C src cd ~/.pyenv && src/configure && make -C src
2. **Define environment variable `PYENV_ROOT`** to point to the path where 2. **Configure your shell's environment for Pyenv**
pyenv repo is cloned and add `$PYENV_ROOT/bin` to your `$PATH` for access
to the `pyenv` command-line utility.
- For **bash**/**Zsh**: **Note:** The below instructions for specific shells are designed for common shell setups.
~~~ bash If you have an uncommon setup and they don't work for you,
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile use the guidance text and the [Advanced Configuration](#advanced-configuration)
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile section below to figure out what you need to do in your specific case.
echo 'eval "$(pyenv init --path)"' >> ~/.profile
~~~ 1. **Adjust the session-wide environment for your account.** Define
the `PYENV_ROOT` environment variable to point to the path where
you cloned the Pyenv repo, add the `pyenv` command-line utility to your `PATH`,
run the output of `pyenv init --path` to enable shims.
These commands need to be added into your shell startup files in such a way
that _they are executed only once per session, by its login shell._
This typically means they need to be added into a per-user shell-specific
`~/.*profile` file, _and_ into `~/.profile`, too, so that they are also
run by GUI managers (which typically act as a `sh` login shell).
- For **Fish shell**: **MacOS note:** If you installed Pyenv with Homebrew, you don't need
to add the `PYENV_ROOT=` and `PATH=` lines.
You also don't need to add commands into `~/.profile` if your shell doesn't use it.
- For **bash**:
Execute this interactively: ~~~ bash
~~~ fish echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
set -Ux PYENV_ROOT $HOME/.pyenv echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths echo 'eval "$(pyenv init --path)"' >> ~/.profile
~~~ ~~~
And add this to `~/.config/fish/config.fish`: - **If your `~/.profile` sources `~/.bashrc` (Debian, Ubuntu, Mint):**
~~~ fish
status is-login; and pyenv init --path | source
~~~
If fish is not your login shell, also follow the bash/zsh instructions to add to ~/.profile. Put these lines into `~/.profile` _before_ the part that sources `~/.bashrc`:
~~~bash
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
~~~
- **Proxy note**: If you use a proxy, export `http_proxy` and `https_proxy` too. **Note:** If you have `~/.bash_profile`, make sure that it too executes the above-added commands,
e.g. by copying them there or by `source`'ing `~/.profile`.
3. **Add `pyenv init` to your shell** to enable shims and autocompletion. - For **Zsh**:
Please make sure `eval "$(pyenv init -)"` is placed toward the end of the shell
configuration file since it manipulates `PATH` during the initialization.
- For **bash**: Same as for Bash above, but add the commands into both `~/.profile`
~~~ bash and `~/.zprofile`.
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
~~~ - For **Fish shell**:
- For **Zsh**: Execute this interactively:
~~~ zsh ~~~ fish
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc set -Ux PYENV_ROOT $HOME/.pyenv
~~~ set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths
~~~
- For **Fish shell**: And add this to `~/.config/fish/config.fish`:
Add this to `~/.config/fish/config.fish`: ~~~ fish
~~~ fish status is-login; and pyenv init --path | source
pyenv init - | source ~~~
~~~
**General warning**: There are some systems where the `BASH_ENV` variable is configured If Fish is not your login shell, also follow the Bash/Zsh instructions to add to `~/.profile`.
to point to `.bashrc`. On such systems you should almost certainly put the above mentioned line
`eval "$(pyenv init -)"` into `.bash_profile`, and **not** into `.bashrc`. Otherwise you
may observe strange behaviour, such as `pyenv` getting into an infinite loop.
See [#264](https://github.com/pyenv/pyenv/issues/264) for details.
4. **Restart your shell so the path changes take effect.** **Proxy note**: If you use a proxy, export `http_proxy` and `https_proxy`, too.
You can now begin using pyenv.
```sh 2. **Add `pyenv` into your shell** by running the output of `pyenv init -`
exec "$SHELL" to enable autocompletion and all subcommands.
```
This command needs to run at startup of any interactive shell instance.
In an interactive login shell, it needs to run _after_ the commands
from the previous step.
- For **bash**:
~~~ bash
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
~~~
- **If your `/etc/profile` sources `~/.bashrc` (SUSE):**
~~~bash
echo 'if command -v pyenv >/dev/null; then eval "$(pyenv init -)"; done' >> ~/.bashrc
~~~
- For **Zsh**:
~~~ zsh
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
~~~
- For **Fish shell**:
Add this to `~/.config/fish/config.fish`:
~~~ fish
pyenv init - | source
~~~
**General warning**: There are some systems where the `BASH_ENV` variable is configured
to point to `.bashrc`. On such systems you should almost certainly put the above-mentioned line
`eval "$(pyenv init -)"` into `.bash_profile`, and **not** into `.bashrc`. Otherwise you
may observe strange behaviour, such as `pyenv` getting into an infinite loop.
See [#264](https://github.com/pyenv/pyenv/issues/264) for details.
4. **Restart your login session for the changes to take effect.**
E.g. if you're in a GUI session, you need to fully log out and log back in.
5. [**Install Python build dependencies**](https://github.com/pyenv/pyenv/wiki#suggested-build-environment) before attempting to install a new Python version. 5. [**Install Python build dependencies**](https://github.com/pyenv/pyenv/wiki#suggested-build-environment) before attempting to install a new Python version.
@ -271,26 +313,26 @@ easy to fork and contribute any changes back upstream.
```sh ```sh
pyenv install 2.7.8 pyenv install 2.7.8
``` ```
**NOTE:** If you need to pass configure option to build, please use **NOTE:** If you need to pass a `configure` option to a build, please use the
```CONFIGURE_OPTS``` environment variable. ```CONFIGURE_OPTS``` environment variable.
**NOTE:** If you want to use proxy to download, please use `http_proxy` and `https_proxy` **NOTE:** If you want to use proxy to download, please set the `http_proxy` and `https_proxy`
environment variable. environment variables.
**NOTE:** If you are having trouble installing a python version, **NOTE:** If you are having trouble installing a Python version,
please visit the wiki page about please visit the wiki page about
[Common Build Problems](https://github.com/pyenv/pyenv/wiki/Common-build-problems) [Common Build Problems](https://github.com/pyenv/pyenv/wiki/Common-build-problems).
#### Upgrading #### Upgrading
If you've installed pyenv using homebrew, upgrade using: If you've installed Pyenv using Homebrew, upgrade using:
```sh ```sh
brew upgrade pyenv brew upgrade pyenv
``` ```
If you've installed pyenv using the instructions above, you can If you've installed Pyenv using the instructions above, you can
upgrade your installation at any time using git. upgrade your installation at any time using Git.
To upgrade to the latest development version of pyenv, use `git pull`: To upgrade to the latest development version of pyenv, use `git pull`:
@ -299,7 +341,7 @@ cd $(pyenv root)
git pull git pull
``` ```
To upgrade to a specific release of pyenv, check out the corresponding tag: To upgrade to a specific release of Pyenv, check out the corresponding tag:
```sh ```sh
cd $(pyenv root) cd $(pyenv root)
@ -313,24 +355,29 @@ git checkout v0.1.0
The simplicity of pyenv makes it easy to temporarily disable it, or The simplicity of pyenv makes it easy to temporarily disable it, or
uninstall from the system. uninstall from the system.
1. To **disable** pyenv managing your Python versions, simply remove the 1. To **disable** Pyenv managing your Python versions, simply remove the
`pyenv init` line from your shell startup configuration. This will `pyenv init` invocations from your shell startup configuration. This will
remove pyenv shims directory from PATH, and future invocations like remove Pyenv shims directory from `PATH`, and future invocations like
`python` will execute the system Python version, as before pyenv. `python` will execute the system Python version, as it was before Pyenv.
`pyenv` will still be accessible on the command line, but your Python `pyenv` will still be accessible on the command line, but your Python
apps won't be affected by version switching. apps won't be affected by version switching.
2. To completely **uninstall** pyenv, perform step (1) and then remove 2. To completely **uninstall** Pyenv, remove _all_ configuration lines for it
from your shell startup configuration, and then remove
its root directory. This will **delete all Python versions** that were its root directory. This will **delete all Python versions** that were
installed under `` $(pyenv root)/versions/ `` directory: installed under `` $(pyenv root)/versions/ `` directory:
```sh
rm -rf $(pyenv root) ```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 If you've installed Pyenv using a package manager, as a final step,
perform the Pyenv package removal. For instance, for Homebrew:
```
brew uninstall pyenv
```
### Advanced Configuration ### Advanced Configuration
@ -338,8 +385,11 @@ Skip this section unless you must know what every line in your shell
profile is doing. profile is doing.
`pyenv init` is the only command that crosses the line of loading `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 extra commands into your shell. Coming from RVM, some of you might be
opposed to this idea. Here's what `pyenv init` actually does: opposed to this idea. Here's what `pyenv init` actually does.
Step 1 is done by `eval "$(pyenv init --path)"`, the others are done by
`eval "$(pyenv init -)"`.
1. **Sets up your shims path.** This is the only requirement for pyenv to 1. **Sets up your shims path.** This is the only requirement for pyenv to
function properly. You can do this by hand by prepending function properly. You can do this by hand by prepending
@ -361,12 +411,13 @@ opposed to this idea. Here's what `pyenv init` actually does:
for some reason you need `pyenv` to be a real script rather than a for some reason you need `pyenv` to be a real script rather than a
shell function, you can safely skip it. shell function, you can safely skip it.
To see exactly what happens under the hood for yourself, run `pyenv init -`. To see exactly what happens under the hood for yourself, run `pyenv init -`
or `pyenv init --path`.
If you don't want to use `pyenv init` and shims, you can still benefit 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 from pyenv's ability to install Python versions for you. Just run
`pyenv install` and you will find versions installed in `pyenv install` and you will find versions installed in
`$(pyenv root)/versions`, which you can manually execute or symlink `$(pyenv root)/versions`, which you can manually execute or symlink
as required. as required.
### Uninstalling Python Versions ### Uninstalling Python Versions

View file

@ -75,20 +75,29 @@ function main() {
function help_() { function help_() {
case "$shell" in case "$shell" in
bash ) bash )
profile='~/.bashrc' profile='~/.bash_profile'
rc='~/.bashrc'
;; ;;
zsh ) zsh )
profile='~/.zshrc' profile='~/.zprofile'
rc='~/.zshrc'
;; ;;
ksh ) ksh )
profile='~/.profile' profile='~/.profile'
rc='~/.profile'
;; ;;
* ) * )
profile='your profile' profile='your shell'\''s login startup file'
rc='your shell'\''s interactive startup file'
;; ;;
esac esac
{ {
echo
echo '# (The below instructions are intended for common'
echo '# shell setups. See the README for more guidance'
echo '# if they don'\''t apply and/or don'\''t work for you.)'
echo
case "$shell" in case "$shell" in
fish ) fish )
echo "# Add pyenv executable to PATH by running" echo "# Add pyenv executable to PATH by running"
@ -112,27 +121,38 @@ function help_() {
echo echo
;; ;;
* ) * )
echo "# Add pyenv executable to PATH by adding" echo '# Add pyenv executable to PATH and'
echo "# the following to ~/.profile:" echo '# enable shims by adding the following'
case "$shell" in
bash|ksh )
echo '# to ~/.profile:'
;;
* )
echo '# to ~/.profile and '"${profile}"':'
;;
esac
echo echo
echo 'export PYENV_ROOT="$HOME/.pyenv"' echo 'export PYENV_ROOT="$HOME/.pyenv"'
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' echo 'export PATH="$PYENV_ROOT/bin:$PATH"'
echo 'eval "$(pyenv init --path)"'
echo echo
echo "# Load pyenv automatically by appending" if [[ $shell == "bash" ]]; then
echo "# the following to ${profile}:" echo '# If your ~/.profile sources '"${rc}"','
echo '# the lines need to be inserted before the part'
echo '# that does that.'
echo
echo '# If you have '"${profile}"', make sure that it'
echo '# also executes the above lines -- e.g. by'
echo '# copying them there or by sourcing ~/.profile'
echo
fi
echo "# Load pyenv into the shell by adding"
echo "# the following to ${rc}:"
echo echo
echo 'eval "$(pyenv init -)"' echo 'eval "$(pyenv init -)"'
echo echo
echo "# and the following to ~/.profile:"
echo
echo 'eval "$(pyenv init --path)"'
echo
echo '# If your ~/.profile sources '"${profile}"','
echo '# the lines should be inserted before the part'
echo '# that does that.'
echo
echo '# Make sure to restart your entire logon session' echo '# Make sure to restart your entire logon session'
echo '# for changes to ~/.profile to take effect.' echo '# for changes to profile files to take effect.'
echo echo
;; ;;
esac esac