Object Oriented Python 简明教程

Object Oriented Python - Environment Setup

本章将详细解释如何在您的本地计算机上设置 Python 环境。

This chapter will explain in detail about setting up the Python environment on your local computer.

Prerequisites and Toolkits

在继续学习 Python 之前,我们建议您检查是否满足以下先决条件−

Before you proceed with learning further on Python, we suggest you to check whether the following prerequisites are met −

  1. Latest version of Python is installed on your computer

  2. An IDE or text editor is installed

  3. You have basic familiarity to write and debug in Python, that is you can do the following in Python − Able to write and run Python programs. Debug programs and diagnose errors. Work with basic data types. Write for loops, while loops, and if statements Code functions

如果您没有任何编程语言经验,您可以在

If you don’t have any programming language experience, you can find lots of beginner tutorials in Python on

Installing Python

以下步骤详细介绍了如何在本地计算机上安装 Python−

The following steps show you in detail how to install Python on your local computer −

Step 1 − 前往官方 Python 网站 https://www.python.org/ ,单击 Downloads 菜单,然后选择最新或任何稳定的版本。

Step 1 − Go to the official Python website https://www.python.org/, click on the Downloads menu and choose the latest or any stable version of your choice.

python website

Step 2 − 保存您正在下载的 Python 安装程序 exe 文件,下载完成后将其打开。单击 Run ,并默认选择 Next 选项,然后完成安装。

Step 2 − Save the Python installer exe file that you’re downloading and once you have downloaded it, open it. Click on Run and choose Next option by default and finish the installation.

python installer

Step 3 − 安装后,您现在应该会看到如下图所示的 Python 菜单。通过选择 IDLE(Python GUI)来启动程序。

Step 3 − After you have installed, you should now see the Python menu as shown in the image below. Start the program by choosing IDLE (Python GUI).

idle

这将启动 Python shell。键入简单命令来检查安装。

This will start the Python shell. Type in simple commands to check the installation.

python shell

Choosing an IDE

集成开发环境是一个面向软件开发的文本编辑器。您必须安装一个 IDE 来控制您的编程流程,并在处理 Python 时对项目分组。以下是网上提供的一些 IDE。您可以根据自己的需要选择一个。

An Integrated Development Environment is a text editor geared towards software development. You will have to install an IDE to control the flow of your programming and to group projects together when working on Python. Here are some of IDEs avaialable online. You can choose one at your convenience.

  1. Pycharm IDE

  2. Komodo IDE

  3. Eric Python IDE

Note − Eclipse IDE 主要用于 Java,但它有一个 Python 插件。

Note − Eclipse IDE is mostly used in Java, however it has a Python plugin.

Pycharm

pycharm

Pycharm 跨平台 IDE 是目前最流行的 IDE 之一。它通过代码完成、项目和代码导航、集成单元测试、版本控制集成、调试等提供编码辅助和分析

Pycharm, the cross-platform IDE is one of the most popular IDE currently available. It provides coding assistance and analysis with code completion, project and code navigation, integrated unit testing, version control integration, debugging and much more

Languages Supported − Python、HTML、CSS、JavaScript、Coffee Script、TypeScript、Cython、AngularJS、Node.js、模板语言。

Languages Supported − Python, HTML, CSS, JavaScript, Coffee Script, TypeScript, Cython,AngularJS, Node.js, template languages.

Screenshot

screenshot

Why to Choose?

PyCharm 为其用户提供以下功能和好处−

PyCharm offers the following features and benefits for its users −

  1. Cross platform IDE compatible with Windows, Linux, and Mac OS

  2. Includes Django IDE, plus CSS and JavaScript support

  3. Includes thousands of plugins, integrated terminal and version control

  4. Integrates with Git, SVN and Mercurial

  5. Offers intelligent editing tools for Python

  6. Easy integration with Virtualenv, Docker and Vagrant

  7. Simple navigation and search features

  8. Code analysis and refactoring

  9. Configurable injections

  10. Supports tons of Python libraries

  11. Contains Templates and JavaScript debuggers

  12. Includes Python/Django debuggers

  13. Works with Google App Engine, additional frameworks and libraries.

  14. Has customizable UI, VIM emulation available

Komodo IDE

komode

这是一款多语言 IDE,支持 100 多种语言,并且基本适用于动态语言(如 Python、PHP 和 Ruby)。这是一款商业 IDE,可免费试用 21 天,并提供完整功能。ActiveState 是管理 Komodo IDE 开发的软件公司。它还提供 Komodo 的精简版本,称为 Komodo Edit,可用于简单的编程任务。

It is a polyglot IDE which supports 100+ languages and basically for dynamic languages such as Python, PHP and Ruby. It is a commercial IDE available for 21 days free trial with full functionality. ActiveState is the software company managing the development of the Komodo IDE. It also offers a trimmed version of Komodo known as Komodo Edit for simple programming tasks.

这款 IDE 包含各种功能,从最基本到高级级别。如果您是学生或自由职业者,则可以购买价格几乎是实际价格一半的产品。但是,对于受认可机构和大学的老师和教授来说,它是完全免费的。

This IDE contains all kinds of features from most basic to advanced level. If you are a student or a freelancer, then you can buy it almost half of the actual price. However, it’s completely free for teachers and professors from recognized institutions and universities.

它具有进行 Web 和移动开发所需的所有功能,包括对所有语言和框架的支持。

It got all the features you need for web and mobile development, including support for all your languages and frameworks.

Komodo Edit(免费版本)和 Komodo IDE(付费版本)的下载链接如下所示 −

The download links for Komodo Edit(free version) and Komodo IDE(paid version) are as given here −

Komodo Edit (free)

Komodo Edit (free)

Komodo IDE (paid)

Komodo IDE (paid)

Screenshot

komodo ide

Why to Choose?

  1. Powerful IDE with support for Perl, PHP, Python, Ruby and many more.

  2. Cross-Platform IDE.

它包括基本功能,如集成调试器支持、自动完成、文档对象模型 (DOM) 查看器、代码浏览器、交互式 shell、断点配置、代码分析、集成单元测试。简而言之,它是一款专业 IDE,具有大量提高生产力的功能。

It includes basic features like integrated debugger support, auto complete, Document Object Model(DOM) viewer, code browser, interactive shells, breakpoint configuration, code profiling, integrated unit testing. In short, it is a professional IDE with a host of productivity-boosting features.

Eric Python IDE

eric

这是一款用于 Python 和 Ruby 的开源 IDE。Eric 是一个全功能编辑器和 IDE,用 Python 编写。它基于跨平台 Qt GUI 工具包,集成了高度灵活的 Scintilla 编辑器控件。这款 IDE 非常可配置,用户可以选择使用哪些功能,以及不使用哪些功能。您可以从以下链接下载 Eric IDE:

It is an open-source IDE for Python and Ruby. Eric is a full featured editor and IDE, written in Python. It is based on the cross platform Qt GUI toolkit, integrating the highly flexible Scintilla editor control. The IDE is very much configurable and one can choose what to use and what not. You can download Eric IDE from below link:

Why to Choose

  1. Great indentation, error highlighting.

  2. Code assistance

  3. Code completion

  4. Code cleanup with PyLint

  5. Quick search

  6. Integrated Python debugger.

Screenshot

why to choose

Choosing a Text Editor

您可能并不总需要 IDE。例如,学习使用 Python 或 Arduino 进行编码的任务,或者在 shell 脚本中处理快速脚本以帮助您自动执行某些任务时,一款简单且轻量级的以代码为中心的文本编辑器就足够了。此外,许多文本编辑器提供诸如语法高亮显示和程序内脚本执行等功能,类似于 IDE。以下列出了一些文本编辑器 −

You may not always need an IDE. For tasks such as learning to code with Python or Arduino, or when working on a quick script in shell script to help you automate some tasks a simple and light weight code-centric text editor will do. Also many text editors offer features such as syntax highlighting and in-program script execution, similar to IDEs. Some of the text editors are given here −

  1. Atom

  2. Sublime Text

  3. Notepad++

Atom Text Editor

atom

Atom 是一款由 GitHub 团队开发的可破解文本编辑器。这是一款免费且开放源代码的文本和代码编辑器,这意味着您可以查看所有代码、针对您自己的用途进行修改,甚至还可以提供改进建议。这是一款适用于 macOS、Linux 和 Microsoft Windows 的跨平台文本编辑器,支持以 Node.js 编写的外挂程序和嵌入式 Git 控制。

Atom is a hackable text editor built by the team of GitHub. It is a free and open source text and code editor which means that all the code is available for you to read, modify for your own use and even contribute improvements. It is a cross-platform text editor compatible for macOS, Linux, and Microsoft Windows with support for plug-ins written in Node.js and embedded Git Control.

Screenshot

download link

Languages Supported

C/C++、C#、CSS、CoffeeScript、HTML、JavaScript、Java、JSON、Julia、Objective-C、PHP、Perl、Python、Ruby on Rails、Ruby、Shell 脚本、Scala、SQL、XML、YAML 等多种语言。

C/C++, C#, CSS, CoffeeScript, HTML, JavaScript, Java, JSON, Julia, Objective-C, PHP, Perl, Python, Ruby on Rails, Ruby, Shell script, Scala, SQL, XML, YAML and many more.

Sublime Text Editor

sublime

Sublime Text 是一个专有软件,它提供了免费试用版,让您在购买前进行测试。根据 stackoverflow.com 的说法,它是第四大最受欢迎的开发环境。

Sublime text is a proprietary software and it offers you a free trial version to test it before you purchase it. According to stackoverflow.com, it’s the fourth most popular Development Environment.

它提供的一些优势包括其令人难以置信的速度、易用性和社区支持。它还支持多种编程语言和标记语言,用户可以通过插件添加函数,这些插件通常由社区创建并在自由软件许可下维护。

Some of the advantages it provides is its incredible speed, ease of use and community support. It also supports many programming languages and mark-up languages, and functions can be added by users with plugins, typically community-built and maintained under free-software licenses.

Screenshot

freesoftware licenses

Language supported

  1. Python, Ruby, JavaScript etc.

Why to Choose?

  1. Customize key bindings, menus, snippets, macros, completions and more.

  2. Auto completion feature

  3. Quickly Insert Text & code with sublime text snippets using snippets, field markers and place holders

  4. Opens Quickly

  5. Cross Platform support for Mac, Linux and Windows.

  6. Jump the cursor to where you want to go

  7. Select Multiple Lines, Words and Columns

Notepad ++

notepad

这是一款免费源代码编辑器,取代记事本,支持多种语言,从汇编语言到 XML,包括 Python。在 MS Windows 环境中运行,其使用受 GPL 许可约束。除语法高亮显示外,Notepad++ 还拥有对编码人员特别有用的某些功能。

It’s a free source code editor and Notepad replacement that supports several languages from Assembly to XML and including Python. Running in the MS windows environment, its use is governed by GPL license. In addition to syntax highlighting, Notepad++ has some features that are particularly useful to coders.

Screenshot

notepad plusplus

Key Features

  1. Syntax highlighting and syntax folding

  2. PCRE (Perl Compatible Regular Expression) Search/Replace

  3. Entirely customizable GUI

  4. SAuto completion

  5. Tabbed editing

  6. Multi-View

  7. Multi-Language environment

  8. Launchable with different arguments

Language Supported

  1. Almost every language (60+ languages) like Python, C, C++, C#, Java etc.