Mac Catalina 10.15.1 .bash_profile 配置Python路径不生效

遇到的问题

mac系统更新到Mac Catalina 10.15.1
终端执行python,始终为系统默认的Python版本。

因为是使用pyenv管理Python版本,故查看当前的Python版本:

% pyenv versions
  system
* 3.7.4 (set by /Users/wuxiaoxin/.pyenv/version)

当前的Python版本没错,但是终端执行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, Oct 17 2019, 17:14:30) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin
Type "help", "copyright", "credits" or "license" for more information.

苹果搞鬼???

检查了下 .bash_profile 文件的配置,没错啊

...(此处省略一百字)
export PYENV_ROOT=~/.pyenv
export PATH=$PYENV_ROOT/shims:$PATH

难道 .bash_profile不加载?假设就是不加载。

解决方式

打开.zlogin

open ~/.zlogin

加上这两行并保存:

if [ -f ~/.bash_profile ]; then
    source ~/.bash_profile
fi

重启终端,居然可以了!

. zlogin应该是mac系统终端启动时加载的配置文件,因此在启动终端,判断.bash_profile是否加载,如果没有加载则自动加载一下。

参考

http://blog.xsudo.com/2019/04/12/1445/

你可能感兴趣的:(Mac Catalina 10.15.1 .bash_profile 配置Python路径不生效)