Linux CentOS 7,如何将Python2.7设置为默认的Python版本?

2024-05-19 21:14:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我在用一台运行LinuxCentOS7的笔记本电脑。 我安装了Python2.7,然后安装了Anaconda,它安装了Python3.5.2

我希望我的系统使用Python2.7作为默认值,但如果我在终端键入python,它将从Anaconda启动Python3.5.2:

[davide@opennet-33-58 ~]$ python
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

我试着把Python3取下来,但它还在。。。

如何将Python2.7设置为机器上的默认Python版本?

谢谢


Tags: 终端default键入hat系统custombitred
3条回答

最简单的方法:只需在/home/.bashrc中添加一个别名,如下所示:

alias python="/usr/bin/python3.5"

(我想CentOS的结构与Linux Mint相似)

但您可能应该使用virtual env,here's链接来开始。解决这样的问题是虚拟环境的主要目的。

给他/她。 如果你没有回购协议,你需要启用正确的回购协议

subscription-manager repos --enable=rhel-6-server-optional-rpms

subscription-manager repos --enable=rhel-server-rhscl-6-rpms

然后安装

yum install scl-utils
yum install centos-release-scl-rh  (only for Centos)
yum install python27  (or any version you need to install)

现在安装了新的python,您必须将其作为默认设置启用

scl enable python27 bash (with this command will be default until you logout,is good to test the changes)

保持变化 您应该在/etc/profile.d/下创建一个脚本

#!/bin/bash
source scl_source enable python27

也许你想熟悉替代方案

备选方案创建、删除、维护和显示有关组成备选方案系统的符号链接的信息。替代品系统是Debian替代品系统的重新实现。

Check out this thread在这里,我快速浏览基本命令以实现您的请求,并查看alternatives manpages

相关问题 更多 >