homebrew - 通过 brew 升级 pyenv,现在只在新终端上激活系统 python
问题描述
昨天我通过 brew 从 1.2.24.1 -> 2.0.3 升级了 pyenv。从那时起,当我打开任何新的终端窗口时,python
它链接到内置系统 Python 2 而不是我的全局 pyenv python。
如果我pyenv virtualenvwrapper
在终端窗口中执行 a,然后创建并激活虚拟环境(mkvirtualenv foobar
和workon 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
. 我自己的路:
$ 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 -)"
如果我做 a PYENV_DEBUG=1 pyenv init -
,输出可以在这个要点中看到:https ://gist.github.com/pzelnip/641a862c19f35571c20fb7d2cb1aabe8
解决方案
更改eval "$(pyenv init -)"
并eval "$(pyenv init --path)"
启动一个新的 shell。
似乎这是在 2.0 中引入的更改
推荐阅读
- css - 使用 Flexbox 重新创建 CSS 网格布局
- javascript - 尝试将函数传递给 axios.then 并捕获时收到错误
- sql-server - 如何生成xml
- wordpress - 域映射不正确。找不到 style.css
- android - 如果 API 请求为浏览器(正确响应)和 Android(不稳定)返回不同的结果,问题可能出在 API 上还是其他问题?
- asp.net - 如何在 .NET Core 的 ViewComponent 中调用 ViewComponent
- c# - C# Json 序列化
- angular - Ionic 4 FileOpener plugin_not_installed
- compression - 一致地压缩文件夹
- java - 如何将按钮放在android java布局的右侧