我的系统默认安装了 Python 2.7.9 :-
amitwebhero@AmitKali:~$ python
Python 2.7.9 (default, Mar 1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
并且我已经安装了它的最新版本 Python 3.5。
amitwebhero@AmitKali:~$ python3.5
Python 3.5.0+ (default, Oct 11 2015, 09:05:38)
[GCC 5.2.1 20151003] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
但是每当我想在终端中编译 python 程序时,我都需要编写 python3.5 file_name.py ,所以我想更改我的默认 python 版本。
但是我已经安装了基于 python 2.7.9 的插件和程序,所以我怀疑如果我将 python 3.5 设置为默认值,那么它可能会导致我使用以前版本的 python 安装的所有插件出现问题。
如果可能,请尝试告诉我是否应该更改我的默认 python?
请您参考如下方法:
首先,它取决于操作系统。对于 Windows - 也许你可以。那里应该没有太多对 Python 的依赖。
但我想你运行的是基于 linux 的操作系统。
例如,对于 centos,您可能会破坏 yum 包管理器 - 据我所知它仍然依赖于 Python2。 Ubuntu 也有很多依赖于 P2 的软件包,尽管他们计划从 16.04 开始迁移到 P3。
为了方便您的工作,您可以添加以下行作为您的 .py 文件的第一行:
#!/usr/bin/env python3
使您的 .py 文件可执行:chmod a+x 并且您可以在没有解释器名称的情况下简单地运行它。
