如何在ubuntu上下载和使用python?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21690009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to download and use python on ubuntu?
提问by user3295015
I recently purchased a system 76 laptop, this is my first exposure to the ubuntu os. Terminal says that I currently have version 2.7.5+(im not sure what the plus means).
最近买了一台system 76的笔记本,这是我第一次接触ubuntu os。终端说我目前有 2.7.5+ 版本(我不确定加号是什么意思)。
My first question is how do I actually use python on this computer since it does not come with idle and my second question is how do I download the newest version 3.3.4 which can be found here: http://python.org/download/releases/3.3.4/?
我的第一个问题是我如何在这台计算机上实际使用 python,因为它没有空闲,我的第二个问题是我如何下载最新版本 3.3.4,可以在这里找到:http: //python.org/download /releases/3.3.4/?
回答by Vasili Syrakis
Upgrading Python (or any package)
升级 Python(或任何包)
$ sudo apt-get update
$ sudo apt-get upgrade python
Using Python
使用 Python
$ python
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "bacon"
bacon
>>>
回答by Rico
If you want python 3, you need to run:
如果你想要 python 3,你需要运行:
sudo apt-get -y install python3.3
If you have an older Ubuntu distro you can download the gzand compile it. This shows an example on how to do it: https://askubuntu.com/questions/244544/how-to-install-python-3-3
如果您有较旧的 Ubuntu 发行版,则可以下载gz并编译它。这显示了如何做到这一点的示例:https: //askubuntu.com/questions/244544/how-to-install-python-3-3
回答by lberezy
To begin, open a console window.
首先,打开一个控制台窗口。
To install Python 3:
要安装 Python 3:
sudo apt-get update
sudo apt-get -y install python3.3
To install IDLE:
安装空闲:
sudo apt-get install idle3
Keep in mind that you can also open a terminal window and simply type pythonto be thrown into a python console. Python 3 may need to be forced with python3if apt as decided not to overwrite your system's default 2.7.5 install.
请记住,您还可以打开一个终端窗口,然后简单地输入python即可将其扔到 Python 控制台中。python3如果 apt 决定不覆盖系统的默认 2.7.5 安装,则可能需要强制使用 Python 3 。
There are also other environments similar to IDLE that can be a lot nicer to use. One such example is a plugin for the Sublime Texttext editor called SublimeREPL(A REPL is a Read Evaluate Print Loop - essentially the interactive python prompt). These REPLs are available for many interpreted languages and can be very handy to have close by when you're writing code.
还有其他类似于 IDLE 的环境可以更好地使用。一个这样的例子是一个Sublime Text名为的文本编辑器插件SublimeREPL(REPL 是一个读取评估打印循环 - 本质上是交互式 python 提示)。这些 REPL 可用于许多解释性语言,并且在您编写代码时非常方便。
Here's what it looks like on my OSX install:
这是我的 OSX 安装时的样子:


回答by Kashif
Now(2020) the latest version for download the python is 3.8 so you install it using
现在(2020)下载python的最新版本是3.8,因此您可以使用
sudo apt install python3.8
by Default python install in ubuntu
so you check version by typing in terminal(Ctrl+Alt+T) python3 -Vif show older version then configure it
type in terminal
通过默认的Python在Ubuntu的安装,所以你通过键入终端(查看版本Ctrl+ Alt+ T)python3 -V,如果显示旧版本,然后将其配置在终端上键入
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8.1
If one more version available then config it in terminal using:
如果还有一个版本可用,则使用以下命令在终端中配置它:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6(any version that already exist in system)
If there are many python versions in your system then you can set any by default to latest version by using this command in terminal:
如果您的系统中有许多 python 版本,那么您可以在终端中使用以下命令将任何默认设置为最新版本:
sudo update-alternatives --config python3
When you hit enter then show you some messages like
当您按 Enter 键时,会向您显示一些消息,例如
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.6 2 auto mode
1 /usr/bin/python3.6 2 manual mode
* 2 /usr/bin/python3.8 1 manual mode
Press <enter> to keep the current choice[*], or type selection number:
According to your configuration it will display versions of python. It depends on your requirement any time you change it like so
if type selection 2then the python latest version set by default
根据您的配置,它将显示 python 的版本。这取决于您在任何时候更改它的要求,如果类型选择2则默认设置为 python 最新版本
python3 -V
Python 3.8.0

