1 pyenv_config_warning() {
2 [[ "$ZSH_PYENV_QUIET" != true ]] || return 0
5 local pyenv_root="${PYENV_ROOT/#$HOME/\$HOME}"
7 Found pyenv, but it is badly configured ($reason). pyenv might not
8 work correctly for non-interactive shells (for example, when run from a script).
10 To fix this message, add these lines to the '.profile' and '.zprofile' files
11 in your home directory:
13 export PYENV_ROOT="$pyenv_root"
14 export PATH="\$PYENV_ROOT/bin:\$PATH"
15 eval "\$(pyenv init --path)"
17 You'll need to restart your user session for the changes to take effect.${(%):-%b%f}
18 For more information go to https://github.com/pyenv/pyenv/#installation.
22 # This plugin loads pyenv into the current shell and provides prompt info via
23 # the 'pyenv_prompt_info' function. Also loads pyenv-virtualenv if available.
25 # Look for pyenv in $PATH and verify that it's not a part of pyenv-win in WSL
26 if ! command -v pyenv &>/dev/null; then
28 elif [[ "${commands[pyenv]}" = */pyenv-win/* && "$(uname -r)" = *icrosoft* ]]; then
34 # Look for pyenv and try to load it (will only work on interactive shells)
35 if [[ $FOUND_PYENV -ne 1 ]]; then
36 pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv" "/usr/local/opt/pyenv")
37 for dir in $pyenvdirs; do
38 if [[ -d "$dir/bin" ]]; then
44 if [[ $FOUND_PYENV -ne 1 ]]; then
45 if (( $+commands[brew] )) && dir=$(brew --prefix pyenv 2>/dev/null); then
46 if [[ -d "$dir/bin" ]]; then
52 # If we found pyenv, load it but show a caveat about non-interactive shells
53 if [[ $FOUND_PYENV -eq 1 ]]; then
54 # Configuring in .zshrc only makes pyenv available for interactive shells
55 export PYENV_ROOT="$dir"
56 export PATH="$PYENV_ROOT/bin:$PATH"
57 eval "$(pyenv init --path)"
59 # Show warning due to bad pyenv configuration
60 pyenv_config_warning 'pyenv command not found in $PATH'
64 if [[ $FOUND_PYENV -eq 1 ]]; then
65 if [[ -z "$PYENV_ROOT" ]]; then
66 # This is only for backwards compatibility with users that previously relied
67 # on this plugin exporting it. pyenv itself does not require it to be exported
68 export PYENV_ROOT="$(pyenv root)"
71 # Add pyenv shims to $PATH if not already added
72 if [[ -z "${path[(Re)$(pyenv root)/shims]}" ]]; then
73 eval "$(pyenv init --path)"
74 pyenv_config_warning 'missing pyenv shims in $PATH'
78 eval "$(pyenv init - --no-rehash zsh)"
80 # If pyenv-virtualenv exists, load it
81 if [[ "$(pyenv commands)" =~ "virtualenv-init" && "$ZSH_PYENV_VIRTUALENV" != false ]]; then
82 eval "$(pyenv virtualenv-init - zsh)"
85 function pyenv_prompt_info() {
86 local version="$(pyenv version-name)"
87 echo "${version:gs/%/%%}"
90 # Fall back to system python
91 function pyenv_prompt_info() {
92 local version="$(python3 -V 2>&1 | cut -d' ' -f2)"
93 echo "system: ${version:gs/%/%%}"
97 unset FOUND_PYENV pyenvdirs dir
98 unfunction pyenv_config_warning