通过 brew 升级了 pyenv,现在只有系统 python 在新终端上激活

Upgraded pyenv by brew, now only system python activated on new terminal

昨天我通过 brew 从 1.2.24.1 -> 2.0.3 升级了 pyenv。从那时起,当我打开任何新终端 window 时,python 链接到内置系统 Python 2 而不是我的全局 pyenv python.

如果我在终端 window 中执行 pyenv virtualenvwrapper,然后创建并激活虚拟环境(mkvirtualenv foobarworkon foobar),那么我的全局 pyenv Python 被正确激活。例如:

$ pyenv global
3.9.6

$ which python
/usr/bin/python

$ python

WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Mar 25 2021, 03:11:28)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

$ pyenv virtualenvwrapper

$ mkvirtualenv foobar

created virtual environment CPython3.9.6.final.0-64 in 346ms
  creator CPython3Posix(dest=/Users/adam.parkin/.envs/foobar, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/adam.parkin/Library/Application Support/virtualenv)
    added seed packages: pip==21.1.3, setuptools==57.1.0, wheel==0.36.2
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
virtualenvwrapper.user_scripts creating /Users/adam.parkin/.envs/foobar/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/adam.parkin/.envs/foobar/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/adam.parkin/.envs/foobar/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/adam.parkin/.envs/foobar/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/adam.parkin/.envs/foobar/bin/get_env_details

$ workon foobar

$ python
Python 3.9.6 (default, Jul 19 2021, 19:04:48)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

但我不明白为什么新终端不使用 Pyenv python 而不是系统默认 python?

我的路径似乎指向 /usr/bin 之前的 shims 目录,但 which python 指向 /usr/bin/python。我的路径:

$ echo $PATH
/usr/local/Cellar/pyenv-virtualenv/1.1.5/shims:/Users/adam.parkin/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/adam.parkin/.local/bin:/Users/adam.parkin/bin

如你所见,我安装了 pyenv-virtualenv 插件。

我升级时 brew upgrade pyenv 命令的输出可以在这个要点中找到:https://gist.github.com/pzelnip/ca99bf955fe15f66225a41f597501dff

我的 .bashrc 包含以下与 pyenv 相关的行(这些是我的 bashrc 的最后 3 行):

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

如果我执行 PYENV_DEBUG=1 pyenv init -,可以在这个要点中看到输出:https://gist.github.com/pzelnip/641a862c19f35571c20fb7d2cb1aabe8

eval "$(pyenv init -)" 更改为 eval "$(pyenv init --path)" 并开始新的 shell。

这似乎是 2.0 中引入的更改