如果我打开终端并输入python,我会看到版本是2.7.4。我如何获取Python 3.4?如果我有Sublime Text,是否需要IDLE?
如果我打开终端并输入python,我会看到版本是2.7.4。我如何获取Python 3.4?如果我有Sublime Text,是否需要IDLE?
稳定版的Ubuntu 14.04已安装Python 3.4。您需要使用python3
来使用Python 3.4。例如,要执行脚本file.py
,请使用:
python3 file.py
#!/usr/bin/env python3
chmod +x file.py
来分配可执行权限,然后运行你的Python脚本,使用./file.py
来执行,这将使用Python3来执行。~/.bash_aliases
文件,使用gedit ~/.bash_aliases
命令,并输入以下内容:alias python=python3
source ~/.bash_aliases
python file.py
将python3设置为您的默认Python解释器。
不,您不需要使用IDLE来使用python3解释您的程序。
~/Dropbox/XXX/Pythonfiles/
),然后输入python examplefile.py
(这可能很愚蠢,不是你期望的方式)。python ~/Dropbox/XXX/Pythonfiles/examplefile.py
作为一个整体别名,创建一个自定义别名命令,当你输入该命令时就会执行。#!/usr/bin/env python3
代替#!/usr/bin/python3
,以获得更大的灵活性。 - glarrain.bash_aliases
文件,请输入以下命令:sh -c "echo 'alias python=python3' >> ~/.bash_aliases"
。 - Torben Gundtofte-Bruunpython3 -V
sudo apt-get install idle-python3.4
python
和python2
来运行Python v2(2.7),并使用python3
来运行Python v3(3.4)。自 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。dpkg -l | grep -w python
。$ ./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
alias python=python3
python
仍然得到的是版本2.7.5。python3
终端会自动提示要输入的内容:sudo apt-get install python3-minimal
python3.4
,您将进入Python 3.4.1。python3
而不是python
来调用它。 python -V shows 2.7.6
python3 -V shows 3.4.0