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

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

如果我pyenv virtualenvwrapper在终端窗口中执行 a ,然后创建并激活一个虚拟环境(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 目录,但 awhich python指向/usr/bin/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-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)"并启动新的外壳。

似乎这是 2.0 中引入的更改


以上是通过brew升级pyenv,现在只有系统python在新终端上激活的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>