繁体   English   中英

在 CentOS 中将 python 3 设置为默认 python 版本

[英]Set python 3 as default python version in CentOS

I have installed python 3.6 on my CentOS machine by following the guide at https://linuxize.com/post/how-to-install-python-3-on-centos-7/ , which installs python 3 with the following:

sudo yum install rh-python36

The default python version, however, is still python 2. The guide mentions I can run python 3 by first running scl enable rh-python36 bash , and then python 3 will be used. However, this only works for that session - logging out and back in will revert back to python 2. According to How to set Python3.5.2 as default Python version on CentOS? , python 3 可以设置为默认值,如下:

sudo ln -fs /usr/bin/python3 /usr/bin/python

但是,这对我不起作用,因为由于某种原因,我在/usr/bin/中没有任何 python3 文件 - 我只有pythonpython2python2.7python2.7-configpython2-configpython-config (尽管安装了 python 3 和 yum 如上所述)。

第一次运行

$ scl enable rh-python36 bash

切换 python 版本。

二、运行

$ which python

找出 python3.6 二进制文件的确切路径。

第三,编辑~/.bashrc。

$ vim ~/.bashrc

并添加以下行。

alias python='/opt....(the path you found by "which python")'

并保存文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM