python - Python:使用 anacoda3 安装 python 3 后将 python2 设置为默认值
问题描述
我使用 anaconda3 进行 python3 安装。现在它是我的默认 python:
$ which python
/home/xy/anaconda3/bin/python
$ which python3
/home/xy/anaconda3/bin/python
但我需要 python2 作为我的默认 python。
$ which python2
/usr/bin/python2
我试图编辑我的 .bashrc 如下所示,
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/xy/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/nu
ll)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/xy/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/xy/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/xy/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
通过将 export PATH... 的行更改为
export PATH="$PATH:/home/xy/anaconda3/bin"
它没有改变任何东西。
我应该如何将 python2 设置为默认值?
解决方案
我认为最干净的方法是进行以下更改:
1)编辑您~/.bashrc
并进行以下修改
保留此块。不要编辑它。如果您已经删除它,您可以通过键入重新创建它conda init bash
。
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/xy/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/nu
ll)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/xy/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/xy/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/xy/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
2)确保您/home/xy/anaconda3/bin
没有添加到此块之外的 PATH 中。如果是这样,请删除那些。
3)调用conda config --set auto_activate_base False
你的shell
从现在开始,你必须手动激活 anaconda 环境conda activate base
。如果你不调用这个,你将默认回到你的系统 python。
推荐阅读
- google-sheets - 谷歌表格功能相应地拆分数据
- python - 使用 Python 龙卷风自定义 404 错误页面
- angular - Angular:以相同的形式将对象添加到另一个对象
- css - 当我部署我的应用程序时,CSS 模块没有设置某些元素的样式
- javascript - Cannot get ReadableStream when using fetch
- field - Acumatica - 重命名参考网格字段
- javascript - 如何在包装函数中使用 array.map 并返回映射的数组?
- java - 如何在 MacOS 上获取 Java(使用 JNA)中所有窗口句柄的列表?
- python - 使用 .map() 修改多个 Pandas 列
- datetime - 返回“字符串未被识别为有效日期时间”的日期时间变量。