Ubuntu更改默认python版本的方法
一般Ubuntu默认的Python版本都为2.x, 如何改变Python的默认版本呢?
1.查看系统中都有哪些 Python 的二进制文件可供使用。
ls /usr/bin/python* /usr/bin/python /usr/bin/python2-config /usr/bin/python2-jsonpointer /usr/bin/python3 /usr/bin/python3.6 /usr/bin/python3.6m-config /usr/bin/python-config /usr/bin/python2-jsondiff /usr/bin/python2.7 /usr/bin/python3.5 /usr/bin/python3.6-config /usr/bin/python3m /usr/bin/python2 /usr/bin/python2-jsonpatch /usr/bin/python2.7-config /usr/bin/python3.5m /usr/bin/python3.6m
2.查看版本
python -V 或 python --version
2.基于用户修改 Python 版本:
想要为某个特定用户修改 Python 版本,只需要在其 home 目录下创建一个 alias(别名) 即可。打开该用户的 ~/.bashrc文件,添加新的别名信息来修改默认使用的 Python 版本。
alias python= '/usr/bin/python3.4'
一旦完成以上操作,重新登录或者重新加载 .bashrc 文件,使操作生效。
. ~/.bashrc
- 检查当前的 Python 版本。
python --version
3.在系统级修改 Python 版本
我们可以使用 update-alternatives 来为整个系统更改 Python 版本。以 root 身份登录,首先罗列出所有可用的 python 替代版本信息:
update-alternatives --list python update-alternatives: error: no alternatives for python
如果出现以上所示的错误信息,则表示 Python 的替代版本尚未被 update-alternatives 命令识别。想解决这个问题,我们需要更新一下替代列表,将 python2.7 和 python3.6 放入其中。
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
--install 选项使用了多个参数用于创建符号链接。最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。这个例子中,我们为 /usr/bin/python3.4 设置的优先级为2,所以update-alternatives 命令会自动将它设置为默认 Python 版本。
- 查看版本
python --version
- 接下来,我们再次列出可用的 Python 替代版本。
update-alternatives --list python
- 现在开始,我们就可以使用下方的命令随时在列出的 Python 替代版本中任意切换了。
sudo update-alternatives --config python
- 查看版本
python --version
4.移除替代版本
一旦我们的系统中不再存在某个 Python 的替代版本时,我们可以将其从 update-alternatives 列表中删除掉。例如,我们可以将列表中的 python2.7 版本移除掉。
update-alternatives --remove python /usr/bin/python2.7
- 移除软连接
rm -rf /data/logs ln -s /temp/logs /data/logs
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
20 分钟教你搞懂 Git!
尽管每天你都会用到Git,但也有可能搞不懂它的工作原理。为什么Git可以管理版本?基本命令git add和git commit到底在干什么? 在这篇文章中,我将用一个例子来解释Git的运行过程,帮助你理解Git的工作原理。 初始化 让我们创建一个项目的目录,然后进入该目录。 $ mkdir git-demo-project $ cd git-demo-project 如果想管理项目的版本,那么我们应该做的第一件事情就是通过git init初始化。 $ git init git init只做了一件事情,那就是在项目的根目录下创建.git子目录来保存版本信息。 $ ls .git branches/ config description HEAD hooks/ info/ objects/ refs/ 上述命令显示了.git子目录中的内容。 保存对象 接下来让我们创建一个新的空文件test.txt。 $ touch test.txt 然后把这个文件添加到Git代码库中,这一步将创建test.txt现有内容的一个副本。 $ git hash-object -w test.txt e69de2...
- 下一篇
nginx的fastcgi模块配置与php-fpm配置记录
一、安装fastcgi模块1、yum install php-fpm,php-mysql,php-mbstring,php-gd,php-xmlphp-fpm:PHP FastCGI Process Manager,基于fastcgi协议的php进程管理器。nginx可通过该程序与php完成动态数据交互.php-fpm的工作方式类似于httpd的prefork模型/etc/php-fpm.d/www.conf文件为php-fpm的主配置文件,主要配置项有:listen = 127.0.0.1:9000 ##监听地址listen.allowed_clients = 127.0.0.1 ###允许交互的客户端ipuser = apachegroup = apachepm = dynamic ###使用动态方法pm.max_children = 50 ###一次请求允许的最多资源数pm.start_servers = 5 ###刚开始时启动的进程pm.min_spare_servers = 5 ###最少空闲进程数pm.max_spare_servers = 35 ###最大空闲进程数 2、...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- Linux系统CentOS6、CentOS7手动修改IP地址
- CentOS7安装Docker,走上虚拟化容器引擎之路
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- SpringBoot2全家桶,快速入门学习开发网站教程
- CentOS7设置SWAP分区,小内存服务器的救世主
- Docker快速安装Oracle11G,搭建oracle11g学习环境