标签:bin python alternatives update 默认 Python usr Ubuntu
1.查看基本信息
# 列出所有已安装python
ls /usr/bin/python*
#查看默认的 Python 版本信息:
python --version
2.基于用户修改 默认Python 版本
想要为某个特定用户修改 Python 版本,只需要在其 home 目录下创建一个 alias(别名) 即可。
该操作执行:(打开该用户的 ~/.bashrc文件,添加新的别名信息来修改默认使用的 Python 版本)
alias python='/usr/bin/python3.7'
3. 在系统级修改 Python 版本
问题
如果出现以下所示的错误信息,则表示 Python 的替代版本尚未被 update-alternatives 命令识别。
$ update-alternatives --list python
update-alternatives: error: no alternatives for python
解决:想解决这个问题,我们需要更新一下替代列表,将 python2.7 和 python3.4 放入其中。
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
#update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
#update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
--install 选项使用了多个参数用于创建符号链接。最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。这个例子中,我们为 /usr/bin/python3.4 设置的优先级为2,所以update-alternatives 命令会自动将它设置为默认 Python 版本。
python --version
Python 3.4.2
接下来,我们再次列出可用的 Python 替代版本。
update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.4
现在开始,我们就可以使用下方的命令随时在列出的 Python 替代版本中任意切换了。
update-alternatives --config python
移除替代版本
一旦我们的系统中不再存在某个 Python 的替代版本时,我们可以将其从 update-alternatives 列表中删除掉。例如,我们可以将列表中的 python2.7 版本移除掉。
update-alternatives --remove python /usr/bin/python2.7
#update-alternatives: removing manually selected alternative - switching python to auto mode
#update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
方法2、移除软连接
rm -rf /data/logs
ln -s /temp/logs /data/logs
解决软连接ln报错-bash: /usr/local/bin/mysql: Too many levels of symbolic links
标签:bin,python,alternatives,update,默认,Python,usr,Ubuntu 来源: https://www.cnblogs.com/chenxi188/p/12565398.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。