Python is a very popular and useful programming and scripting language. What makes Python so popular and useful is its rich modules, easy learning, and usage, and being cross-platform. In this tutorial, we will learn how to install Python2, Python3 interpreter, tools, and libraries.
Python是一种非常流行且有用的编程和脚本语言。 Python之所以如此流行和有用,是因为其丰富的模块,易于学习和使用以及跨平台。 在本教程中,我们将学习如何安装Python2,Python3解释器,工具和库。
Python2和Python3 (Python2 vs Python3)
Python3 is the latest version of the Python programming language. Python2 is the previous version which is used for a long time. Python3 provides more performance, features, and modernity according to the Python2. But some Python projects maybe depend on Python2.
Python3是Python编程语言的最新版本。 Python2是以前的版本,已经使用了很长时间。 根据Python2,Python3提供了更多的性能,功能和现代性。 但是某些Python项目可能依赖于Python2。
安装Python 2 (Install Python 2)
Python downloads for Windows are provided from the following link where both Python2 and Python3 can be found here. But we will download the Python2 from the following link.
通过以下链接提供了Windows的Python下载,可在此处找到Python2和Python3。 但是,我们将从以下链接下载Python2。
https://www.python.org/downloads/windows/
https://www.python.org/downloads/windows/
When we click to the Latest Python2 Release
we will be redirected to the Python 2 download page which can be also accessed from the following link. We will select the architecture of the Windows operating system like 32 or 64-bit. In this case, we will download the 64-bit installation MSI file.
当我们单击Latest Python2 Release
我们将被重定向到Python 2下载页面,也可以从以下链接访问该页面。 我们将选择Windows操作系统的体系结构,例如32位或64位。 在这种情况下,我们将下载64位安装MSI文件。
https://www.python.org/downloads/release/python-2716/
https://www.python.org/downloads/release/python-2716/
If we are using Windows 10 we will see the following SmartScreen
warning where we will click to the Run
like below.
如果我们使用的是Windows 10,我们将看到以下SmartScreen
警告,在该警告中,我们将单击“ Run
如下”。
With the following screen, the Python2 installation will start. In the following screen, we have two options in order to select for which users we want to install Python2.
在以下屏幕上,将开始Python2安装。 在以下屏幕中,我们有两个选项,以便选择我们要为哪些用户安装Python2。
Install for all users
will install Python2 for all users currently exist in the operating systemInstall for all users
安装将为操作系统中当前存在的Install for all users
安装Python2Install just for me
will install Python2 for the current user and other operating system users can not use Python2.Install just for me
安装将为当前用户安装Python2,而其他操作系统用户则不能使用Python2。
In the following screen, we will specify the Python2 installation path. All files, libraries, interpreters, and tools will be stored in this path. By default C:\Python27
is used but we can change whatever we want.
在以下屏幕中,我们将指定Python2安装路径。 所有文件,库,解释器和工具都将存储在此路径中。 默认情况下使用C:\Python27
,但我们可以更改所需的任何内容。
In the following screen, we will customize the Python2 installation. We can select the features we want to install. By default, most of the features are selected for installation which is very beneficial. We will also select the Add python.exe to Path
options which is very important.
在以下屏幕中,我们将自定义Python2安装。 我们可以选择要安装的功能。 默认情况下,将选择大多数功能进行安装,这是非常有益的。 我们还将选择非常重要的Add python.exe to Path
选项。
Register Extensions
will set this installation as default Python by changing and setting registry values.Register Extensions
将通过更改和设置注册表值将该安装设置为默认Python。Tcl/Tk
will install features like Tkinter, IDLE, pydoc.Tcl/Tk
将安装Tkinter,IDLE,pydoc等功能。Documentation
will install Python HTMLHelp File.Documentation
将安装Python HTMLHelp File。Utility Scripts
will install some tools.Utility Scripts
将安装一些工具。pip
will install the package manager for Python named Pip.pip
将安装名为Pip的Python软件包管理器。Test suite
will installLib/test
libraries and test suite.Test suite
将安装Lib/test
库和测试套件。Add python.exe to Path
is important because it will add the python interpreter to the operating system environment variables automatically. This will enable us to runpython
command from the command line directly. By default these options is not selected we will select it manually.Add python.exe to Path
很重要,因为它将自动将python解释器添加到操作系统环境变量。 这将使我们能够直接从命令行运行python
命令。 默认情况下,未选中这些选项,我们将手动选择它。
As installing all of these things in Python2 we require Administrator rights which will be provided in the following screen by clicking Yes
.
在Python2中安装所有这些东西时,我们需要管理员权限,这将在下面的屏幕中单击Yes
来提供。
Following screen is about the file copy, registry change phase.
接下来的屏幕是关于文件复制,注册表更改阶段的。
If the Python2 is installed without a problem we will see the following screen which says installation is completed successfully.
如果安装Python2没问题,我们将看到以下屏幕,表明安装已成功完成。
安装Python 3(Install Python 3)
Python3 is the latest main version of the Python programming language. The minor version for Python3 is 7 which means the latest version for Python is Python3.7. We can download the Python3 installer for the Windows operating system from the following page. There are 32 and 64-bit installers for the Python3. Also web-based installer
can be used to download installation files from the internet but this will require internet access.
Python3是Python编程语言的最新主版本。 Python3的次要版本是7,这意味着Python的最新版本是Python3.7。 我们可以从下一页下载适用于Windows操作系统的Python3安装程序。 Python3有32位和64位安装程序。 也可以使用web-based installer
从Internet下载安装文件,但这需要Internet访问。
https://www.python.org/downloads/release/python-374/
https://www.python.org/downloads/release/python-374/
We will start the installation process of the Python3 by clicking the downloaded installer and the first screen provides us some options.
通过单击下载的安装程序,我们将开始Python3的安装过程,第一个屏幕为我们提供了一些选项。
Install Now
will install the Python3 directly without ant customization options.Install Now
安装将直接安装Python3,而无需提供蚂蚁自定义选项。Customize installation
will provide some options for the Python3 installation.Customize installation
将为Python3安装提供一些选项。Add Python 3.7 to PATH
will add Python3 interpreter and command to the Windows PATH where the python command can be run directly.Add Python 3.7 to PATH
会将Python3解释器和命令添加到Windows PATH,可直接运行python命令。
We will select the Customize Installation where we want to see and set some options.
我们将选择要查看的“定制安装”并设置一些选项。
Documentation
will install Python documentation files which can be helpful in internet isolated situations.Documentation
将安装Python文档文件,这在互联网隔离的情况下可能会有所帮助。pip
will install Python package manager named Pip which can install, update, and remove 3rd party Python packages, modules, and libraries.pip
将安装名为Pip的Python软件包管理器,该软件包管理器可以安装,更新和删除第三方Python软件包,模块和库。tcl/tk and IDLE
will install Tkinter libraries with the IDLE development environment.tcl/tk and IDLE
将在IDLE开发环境中安装Tkinter库。Python test suite
will install a standard library test suite.Python test suite
将安装标准库测试套件。
We will click to Next and will see the following Advanced Options
screen.
我们将单击“下一步”,然后将看到以下“ Advanced Options
屏幕。
Install for all users
will install Python3 for all the users for the operating systemsInstall for all users
安装将为操作系统的Install for all users
安装Python3Associate files with Python
will set the IDLE default editor for the Python or *.py extension files将
Associate files with Python
将为Python或* .py扩展文件设置IDLE默认编辑器Create shortcuts for installed applications
will create shortcuts for Python interactive shell, IDLE, etc.Create shortcuts for installed applications
创建快捷方式将为Python交互式shell,IDLE等创建快捷方式。Add Python to environment variables
will add python interpreters and commands to the environment variables to execute them directly from the command line.Add Python to environment variables
会将python解释器和命令添加到环境变量,以直接从命令行执行它们。Precompiled standard library
will also install the Python standard library as of Python source code, not DLL.Precompiled standard library
也将从Python源代码开始安装Python标准库,而不是DLL。Download debugging symbols
will download debug symbols for the libraries which can be useful for debuggingDownload debugging symbols
将下载库的调试符号,这对于调试很有用Download debug binaries
Download debug binaries
Customize install location
will specify the installation path for the Python3 which is the current user home directory.Customize install location
将指定Python3的安装路径,这是当前用户的主目录。
Then we will click to the Install
to start the installation process. During the installation, we will see a similar screen to the following where the bar will show the installation percentage.
然后,我们将单击“ Install
以开始安装过程。 在安装过程中,我们将看到与以下类似的屏幕,其中的栏将显示安装百分比。
After the installation is successful we will see the following Setup was successful
screen. We can click the Close
button but we can also click to Diable path length limit
which will bypass the MAX_PATH limitation.
安装成功后,我们将看到以下“ Setup was successful
屏幕。 我们可以单击“ Close
按钮,但也可以单击“ Diable path length limit
,它将绕过MAX_PATH限制。
非交互式Python安装 (Non-interactive Python Installation)
In the previous part, we have installed Python2 and Python3 interactively by using a GUI and clicking the Next buttons. We have also provided some configuration via checkboxes by enabling and disabling them. The Non-interactive Python Installation
will install Python2 via MS-DOS command line with no user interaction. We will just provide some parameters to the non-interactive installation for install configuration. For normal installation, we will just use msiexe
command /i
option for installation and provide the Python MSI installation file path and name.
在上一部分中,我们已经通过使用GUI并单击“下一步”按钮以交互方式安装了Python2和Python3。 我们还通过启用和禁用复选框的方式提供了一些配置。 Non-interactive Python Installation
将通过MS-DOS命令行安装Python2,而无需用户交互。 我们将仅向非交互式安装提供一些参数以进行安装配置。 对于常规安装,我们将仅使用msiexe
命令/i
选项进行安装,并提供Python MSI安装文件的路径和名称。
> msiexec /i python-2.5.msi
For more detailed configuration some options and values can be provided to change default options like installation path, user, GUI.
对于更详细的配置,可以提供一些选项和值来更改默认选项,例如安装路径,用户,GUI。
- /qn – No interface / qn –无界面
- /qb – Basic interface – just a small progress dialog/ qb –基本界面–只是一个小的进度对话框
- /qb! – Like /qb, but hide the Cancel button / qb! –与/ qb类似,但隐藏“取消”按钮
- /qr – Reduced interface – display all dialogs that don’t require user interaction (skip all modal dialogs)/ qr –精简界面–显示不需要用户交互的所有对话框(跳过所有模式对话框)
- /qn+ – Like /qn, but display “Completed” dialog at the end / qn + –与/ qn类似,但在末尾显示“已完成”对话框
- /qb+ – Like /qb, but display “Completed” dialog at the end/ qb + –与/ qb类似,但在末尾显示“已完成”对话框
- TARGETDIR=D:\python2 for installation target directoryTARGETDIR = D:\ python2用于安装目标目录
- ALLUSERS=1 will install for all users but this requires Administrator privileges for the current MS-DOS or command-line interface.将为所有用户安装ALLUSERS = 1,但这需要当前MS-DOS或命令行界面的管理员权限。
基于Web的/在线Python安装(Web-Based/Online Python Installation)
Normally Python installation executables contain all require data, executable, libraries and binary. There is no need to get extra data from remote. But Web-based Python Installation
only provides the installation executable and all other Python tools are downloaded from the internet or web. All other configurations are the same as the regular Python installation.
通常,Python安装可执行文件包含所有必需的数据,可执行文件,库和二进制文件。 无需从远程获取额外的数据。 但是Web-based Python Installation
仅提供安装可执行文件,而所有其他Python工具都是从Internet或Web下载的。 所有其他配置与常规Python安装相同。
使用Chocolatey Package Manager安装和更新Python2或Python3 (Install and Update Python2 or Python3 With Chocolatey Package Manager)
Chocolatey
is a package manager for Windows operating systems similar to the apt and dnf for Linux distributions. Python can be installed via Chocolatey with a single command. Following command will install the latest Python3 release to the current Windows operating system.
Chocolatey
是Windows操作系统的软件包管理器,类似于Linux发行版的apt和dnf。 可以通过Chocolatey使用单个命令安装Python。 以下命令会将最新的Python3版本安装到当前Windows操作系统。
> choco install python
Also already install Python can be updated/upgraded to the latest version with the following command.
还可以使用以下命令将已经安装的Python更新/升级到最新版本。
> choco upgrade python
If we do not need the Python we can use the chocolatey package manager in order to remove/uninstall currently installed Python.
如果我们不需要Python,则可以使用Chocolatey Package Manager来删除/卸载当前安装的Python。
> choco uninstall python
检查并验证Python版本 (Check and Verify Python Version)
We can check the installed Python version in different ways. python
or Python
is the general name where it will redirect to the default Python version which can be Python2 or Python3.
我们可以通过不同的方式检查已安装的Python版本。 python
或Python
是通用名称,它将重定向到默认的Python版本,可以是Python2或Python3。
> python --version
> python
> pip -V
We can check the Python2 or Python3 version in detail by just running their specific commands like below.
我们可以通过仅运行如下所示的特定命令来详细检查Python2或Python3版本。
> python2 --version
OR
要么
> python3 --version
打开已安装的Python Shell并运行Python脚本 (Open Installed Python Shell and Run Python Script)
Python provides the IDLE
for creating and running Python scripts. IDLE also works as a interactive shell or command line for Python language. We can open the IDLE from the Programs
of start menu under the Python
item like below. Alternatively we can type the Python IDLE
to the start menu where Python IDLE will be listed.
Python提供了IDLE
用于创建和运行Python脚本。 IDLE还可以用作Python语言的交互式shell或命令行。 我们可以从Python
项下的开始菜单的Programs
中打开IDLE,如下所示。 或者,我们可以在开始菜单中键入Python IDLE
,在该菜单中将列出Python IDLE。
Python IDLE or Shell can run Python commands and script.
Python IDLE或Shell可以运行Python命令和脚本。
翻译自: https://www.poftut.com/how-to-install-python-python2-and-python3-on-windows/