Python 2.7.5和Python 3.6.5

2024-10-01 04:44:31 发布

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

我已经安装了python3.6.5,但是当我输入Python时,它显示python2.7.5。 我喜欢使用python3。在

[aravind@aravind05 Python-3.6.5]$ python3 --version
Python 3.6.5

[aravind@aravind05 Python-3.6.5]$ python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

我想用python3


Tags: defaultonversionhattypehelpredapr
3条回答

正如Klaus在评论中所说,更改系统Python版本可能会破坏系统。在

相反,使用virtualenv。Here是一个很好的解释,如果你需要帮助的话。在

因为您的系统中都安装了Python的两个版本,所以您需要将默认的Python指向python3.x。在

Open your .bashrc file nano ~/.bashrc. Type alias python=python3 on to a new line at the top of the file then save the file with ctrl+o and close the file with ctrl+x. Then, back at your command line type source ~/.bashrc. Now your alias should be permanent.

EDIT:

For update alternatives, the priority is an integer. The priority represents which program should be the first used. This article sums it all up pretty well.

下面是相关的问题:https://stackoverflow.com/a/41986843/4982185

有多种方法可以实现这一点。在

假设您在一些*NIX操作系统上使用类似bourneshell的shell,那么可以定义一个别名alias python python3。在

您还可以将一个名为“python”的符号链接放在前面路径中列出的目录中:

# on debian-like distributions, the following directories should be reasonable
ln -s ~/.local/bin/python "$(which python3)"
# place the following line into your .bashrc
export PATH="~/.local/bin/python:$PATH"

相关问题 更多 >