如何在Ubuntu上安装Python 3.4?

如果我打开终端并键入python,我看到版本是2.7.4。 我如何获得python 3.4? 如果我有崇高的文字,我还需要IDLE吗?

python 3.4安装在Ubuntu 14.04的稳定版本上。 你需要使用python3来使用python 3.4。 例如,要执行脚本file.py ,请使用:

 python3 file.py 

这将使用python 3.4来解释您的程序,或者您可以使用shebang使其可执行。 你的程序的第一行应该是:

 #!/usr/bin/env python3 

然后使用chmod +x file.py分配可执行权限,然后运行python脚本为./file.py ,它将使用python3执行。

如果您希望在终端上键入python时使用python3,则可以使用别名。 要添加新别名,请使用gedit ~/.bash_aliases打开~/.bash_aliases文件,然后键入以下内容:

 alias python=python3 

然后保存并退出并键入

 source ~/.bash_aliases 

然后你可以输入

 python file.py 

使用python3作为默认的python解释器。

不,你不需要IDLE就可以使用python3来解释你的程序。

默认情况下,在现代版本的Ubuntu上安装Python 3,因此您应该已经安装了它:

 python3 -V 

安装空闲3:

 sudo apt-get install idle-python3.4 

我的ubuntu桌面遇到了同样的问题。 我的python书告诉我通过在终端中输入python来调用python,但它只调用了之前的python版本2。

  1. 首先检查你是否有python版本3。 打开命令终端,输入

python3

你看到你的确认吗? 完成。

  1. 如果你不这样做; 使用以下命令行安装。

sudo apt-get install python3

希望这可以帮助!

在Ubuntu 14.04上,默认安装了Python 3.4。

根据PEP-394的建议,您可以使用pythonpython2来运行Python v2(2.7)和python3来运行Python v3(3.4)。

在终端类型: python3

终端本身会说输入:

 sudo apt-get install python3-minimal 

这样做,这将安装Python 3.2.3。

然后在终端类型: python3.4 – 你将进入Python 3.4.1。

如果只需要一个脚本,则可以在本地和临时使用别名。

安装Letsencrypt时 ,我收到以下警告:

 $ ./letsencrypt-auto --help InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning 

原因:需要Python 2.7.9,而安装了2.7.5。 Python 3也可以。 我打开脚本并在shebang之后插入以下别名:

 alias python=python3 

然后脚本工作。 当这一切都完成后,这个别名被删除了。 它只适用于此脚本。 所以从终端启动python仍然让我获得2.7.5版本。

Python3.4已经安装在你的系统上,你只需要用python3而不是python来调用它

Ubuntu 18.04 LTS及以上

从Ubuntu 18.04及更高版本开始,您不必安装Python 3,因为默认情况下是这样。

对于Ubuntu 18.04 LTS和Debian Buster,我们希望转换到Python 3.6作为默认(可能只有)Python 3版本。

参考文献:


否则通过以下命令安装:

 sudo apt-get install python3 

然后,要找到多个Python安装,请运行以下命令之一:

 whereis python which -a python python2 python3 locate python 

或者只需输入python命令并按Tab键两次。

要列出已安装的Python包,请运行: dpkg -l | grep -w python dpkg -l | grep -w python

有大量的遗留python应用程序,因此需要python 2.x,但是正如其他人提到的python3 -V显示Python 3.4.0已安装,因此使用Ubuntu 14.x它就在那里。

  python -V shows 2.7.6 python3 -V shows 3.4.0 

知道使用哪种口译员取决于你。