解决Mac更新安装zsh后出现Python虚拟环境的问题

Mac更新以后

如果每次打开终端都提示:

The default interactive shell is now zsh.

To update your account to use zsh, please run `chsh -s /bin/zsh`.

原因是原本使用的是bash风格,提示语告知现在新系统的shell已经更换为zsh,请用此 `chsh -s /bin/zsh` 命令切换。

解决办法:

(1) 不使用bash,切换zsh,`chsh -s /bin/zsh`命令切换即可。

(2) 继续使用bash,但又不想出现提示语,则打开文件:

vim ~/.bash_profile

.bash_profile文件最下方加上:

# macOS Catalina

export BASH_SILENCE_DEPRECATION_WARNING=1

然后保存退出

如果使用zsh 虚拟环境命令无效 参照一下

一、根据步骤,当运行source .bash_profile 报错:

/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks. 
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.

错误原因:Mac安装了2.7和3.x两个版本的python,在安装时使用的是sudo pip3 install virtualenvwrapper
运行的时候默认使用的是python2.x,但在python2.x中不存在对应的模块。(virtualenvwrapper.sh文件内容如下:):

# Locate the global Python where virtualenvwrapper is installed.
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python)"

当不存在VIRTUALENVWRAPPER_PYTHON环境时,会默认选择使用which python(我这里默认是python2),

所以需要将which python 改为 which python3 环境:

VIRTUALENVWRAPPER_PYTHON="$(command \which python3)"

二、首先讲一下问题原因:zsh的配置文件.zshrc 没有配置相关环境变量设置

没有这个文件可以创建一个出来
1、需要将bash 中.bash_profile 环境变量加入zshrc

vim .zshrc

2、添加

source ~/.bash_profile

3、执行下面命令后,问题解决。

source .zshrc

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章