如何在Windows上安装Python(Python2和Python3)?

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/

Python2 and Python3 Download Page
Python2和Python3下载页面

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/

Python2 32 and 64 Bit Installer Download
Python2 32 and 64 Bit Installer Download
Python2 32和64位安装程序下载

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如下”。

SmartScreen Warning For Python2
SmartScreen Warning For Python2
适用于Python2的SmartScreen警告

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 system

    Install for all users安装将为操作系统中当前存在的Install for all users安装Python2

  • Install 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。

Python 2 Install User
Python 2 Install User
Python 2安装用户

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 ,但我们可以更改所需的任何内容。

Specify The Python2 Installation Path
Specify The Python2 Installation Path
指定Python2安装路径

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选项。

Select Features To Install Python2
Select Features To Install Python2
选择要安装Python2的功能
  • 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 install Lib/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 run python 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命令。 默认情况下,未选中这些选项,我们将手动选择它。

LEARN MORE  How To Install Python Pip For Linux?
了解更多如何为Linux安装Python Pip?

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来提供。

Provide Admin Rights For Python2 Installation
Provide Admin Rights For Python2 Installation
提供Python2安装的管理员权限

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没问题,我们将看到以下屏幕,表明安装已成功完成。

Python2 Installation Successful
Python2 Installation Successful
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/

Python3 Installers List For Windows
Python3 Installers List For Windows
Windows的Python3安装程序列表

We will start the installation process of the Python3 by clicking the downloaded installer and the first screen provides us some options.

通过单击下载的安装程序,我们将开始Python3的安装过程,第一个屏幕为我们提供了一些选项。

Select Python3 Installatin Type
选择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.

我们将选择要查看的“定制安装”并设置一些选项。

Select Python3 Installation Optional Features
选择Python3安装可选功能
  • 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将安装标准库测试套件。

LEARN MORE  Python Command Line Arguments with sys.argv
通过sys.argv了解更多Python命令行参数

We will click to Next and will see the following Advanced Options screen.

我们将单击“下一步”,然后将看到以下“ Advanced Options屏幕。

Select Python3 Installation Advanced Options
选择“ Python3安装高级选项”
  • Install for all users will install Python3 for all the users for the operating systems

    Install for all users安装将为操作系统的Install for all users安装Python3

  • Associate 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 debugging

    Download 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以开始安装过程。 在安装过程中,我们将看到与以下类似的屏幕,其中的栏将显示安装百分比。

Python3 Setup Progress
Python3安装进度

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限制。

Python3 Installed Succesfully
成功安装Python3

非交互式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 directory

    TARGETDIR = 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或命令行界面的管理员权限。
LEARN MORE  Memcache Delete Operation with Python Example
通过Python示例了解更多Memcache删除操作

基于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版本。 pythonPython是通用名称,它将重定向到默认的Python版本,可以是Python2或Python3。

> python --version

> python

> pip -V
Check and Verify Python Version
Check and Verify Python Version
检查并验证Python版本

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。

Open Python IDLE
打开Python IDLE

Python IDLE or Shell can run Python commands and script.

Python IDLE或Shell可以运行Python命令和脚本。

Run Python Command On IDLE
在IDLE上运行Python命令

翻译自: https://www.poftut.com/how-to-install-python-python2-and-python3-on-windows/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值