Getting Started with Python Fun 02: properly configured properly installed Python (Windows version) Python Fun Getting 01: Do you really know what Python? Getting Started with Python Fun 01: Do you really know what Python?

<Previous: Python Fun Getting 01: Do you really know what Python?

 

In this part taught you how to go online to download and install the Python runtime environment, this article was written in 2020 Python stable version is 3.8, Windows version is popular Win10, Tell me what the search may have been in 2050 when the paper, but the tutorial any course useful as long as you are using Windown system, but must pay attention to the following points.

This tutorial installed on the computer 2 sets Python environment, the installation section 1-3 native environment, Section 4 of the installation environment Visual Studio Code. If you want a quick start, immediately over the addiction to write code, skip to Section 1-3 starting from Section 4.

1, the official Python website

It is strongly recommended Quguan network download Python (at least to see what is currently the most stable version), Python is not recommended to download the installation files on any other third-party sites, only one reason: can not guarantee that the latest version, in case you downloaded to version 2.0 which is the difference between the two programming languages. Legend Some people also downloaded Python, after the installation has become a hot soup is not, and never learned programming. At the following address:

https://www.python.org

 
Figure 1 official website found on the download page

 

Select the Downloads menu in Windows, into the download page, as shown below:

Beginners should be cautious here loading A, it is recommended to select stable (Stable) and the version of the executable (Excutable) of:

 
2 to find the downloaded installation file

Download the official website speed is very slow drop, there is cure for this pain point, suggesting: Thunder can help us to cure the patient.

2, install Python

Run the downloaded installation file to install it. The following figure, you need to check the following two options.

 

 
3 installation options

Add Python 3.8 to PATH to ensure the selected options: the Python executable join the PATH environment variable, meaning is to let the other programs (such as Python editor, command-line program) can directly call the Python program to run.

3、验证安装

很多小哥哥安装到此就结束了,在此应该进行如下2个功能的验证,如果不成功那么说明您前面的程序有问题,请重新卸载,按照本文勾选好,再来安装一次。

3.1 IDLE环境验证

点击开始菜单,启动Python3.8下面的IDLE。 IDLE是Python最基本的命令行,提供简单的程序编辑和命令行功能,基本上我们今后用不到它。

 
图4 启动原生编辑器

值得一提的是菜单中的 Python 3.8 Manuals ,是Python的语言指南,是学习Python真正的好东东,如果英文在小学6年级之上,建议好好阅读相关章节。

下图是打开IDLE后的界面,>>>这三个大于号就是提示符,提示我们已经进入了python的运行环境。

 

打开后,我们输入如下的语句 1+1,看看是不是返回2了。GOOD,恭喜你,学会了加法!

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license()" for more information.

>>> 1+1
2
 >>>


>>>这个符号是命令模式的提示符,用来提示用户输入语句。验证成功后,我们再来验证在命令行下如何运行Python的源程序。

3.2 命令行环境运行Python

通过如下的步骤打开Windows的命令行环境,右击 开始菜单 -> “命令提示符(管理员)”,可以打开如下的命令行,为了方便今后运行程序,我们

 

 
右击开始菜单

在命令行中,如下图,输入下面的命令,这是一个拷贝命令,用来把con就是控制台copy到文件test.py文件。用人话说就是新建一个test.py文件。

copy con test.py           输入这个命令回车后,DOS命令行提示符会消失,输入如下的python程序:

print('Hello World!')    输完后按下回车,再按下键盘上的 Ctrl+Z 键,然后再按下回车,就可以保存文件

 
命令行验证

如上图,我们创建了一个Python的程序后,直接在命令行运行它,在命令行中直接输入这个文件名称test.py如果你看到返回了程序运行的结果Hello World!说明验证成功,如果有问题,那么重新安装上面的文件。

4、安装Visual Studio Code编辑器

初学者在学习代码时,使用顺手的编辑器,才能方便学习。很多专业人士推荐PyCharm,其实无论使用哪一个简单易用不出问题才是最好,所以这里我们推荐大家使用微软的Visual Studio Code编辑器,免费简单并且所有的东西都是一键安装。

4.1 首先找到Visual Studio Code官网

这是官方下载的地址,如下图选择正确的版本下载,安装后会启动。

https://visualstudio.microsoft.com/zh-hans/downloads/

 

 
官网下载才可靠

4.2 新建个文件夹放程序

安装完毕后,打开Visual Studio Code程序,

如下图点击“Open Folder ” 打开一个文件夹。

 
打开文件夹

在弹出的对话框中,新建一个文件夹python,用来放源程序,并且选择它。

 

 

如下图,点击“新建文件” 按钮,再新建一个文件: first.py

 

 
新建.py文件

4.3 安装VS内的Python环境

创建好.py文件后,我们把鼠标移到右边窗口,这时神奇的事情出现了,右下角弹出提示,如下图:

 
自动提示

直接点击install,安装Python运行的环境,这其实和我们第1步安装的Python是完全重复的,但是为减少编辑器的设置工作,安装2个Python又有什么关系呢?如果没有弹出窗口,也可以使用如下的方法找到Python组件。

 

 
安装扩展组件方式

点击左边栏内搜索到的Python组件,主窗口中点击Install,进行安装。

 
安装Python

安装完毕,立刻在右边又出来了如下的提示窗口:

这是Python的组件,pylint用来对Python代码进行智能提示和着色的。

 
Python的组件

可以直接点击Install进行安装,如果没有弹出这个窗口,可以使用Python的pip工具后续补安装,在DOS命令提示里输入:

>pip install pylint    就可以安装pylint

4.4 编写测试代码

下面我们使用如下代码测试一下Python安装的情况:

import random
print(random.randint(1,9))

本程序打印一个1-9的随机数,写好后,右击窗口,选择“在终端窗口中运行文件”,如下图:

 
运行文件

可以看到在主窗口下方的“TERMINAL” 终端窗口里,给出了运行的结果:4

 
运行结果

上图的第1、2行其实是生成的DOS环境的命令,可以看到它调用了刚刚安装的python来运行这个文件;

第3行是运行结果。

 

< 上一篇:Python趣味入门01:你真的了解Python么?

Guess you like

Origin www.cnblogs.com/dosboy/p/python_book_02.html