文章目录

  • 一、Python安装
  • 下载
  • 安装
  • 验证
  • 二、第一个Python程序
  • 常见问题
  • 三、Python解释器
  • 四、PyCharm工具安装和配置
  • 安装
  • 使用
  • PyCharm基本使用


一、Python安装

下载

如果我们想要使用Python语言编写程序,我们必须下载Python安装包并配置Python环境,我们现在就来下载一下Python安装包。

Python官方网站

idea怎么指定python运行路径 idea怎么配置python环境_开发语言


点击下载按钮

idea怎么指定python运行路径 idea怎么配置python环境_idea怎么指定python运行路径_02


我们选择合适的Python版本

idea怎么指定python运行路径 idea怎么配置python环境_python_03


这里我直接下载最新版Python3.12

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_04


下载速度是十分快的,然后我们进行安装操作

安装

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_05


然后我们在文件夹找到安装包双击

idea怎么指定python运行路径 idea怎么配置python环境_ide_06


这里一定要勾选我红色圈出来的选项,然后选择自定义安装

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_07


这里默认都是全选的,然后直接next即可

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_08


在这里我们需要配置一下Python的默认安装路径,注意不要出现中文路径

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_09


这里我就放在了D盘里面,然后点击安装即可

idea怎么指定python运行路径 idea怎么配置python环境_python_10


然后选择忽略长度限制选项即可

idea怎么指定python运行路径 idea怎么配置python环境_ide_11

验证

如何验证我们的Python环境是配置好了的

我们按Win + R 然后输入cmd

idea怎么指定python运行路径 idea怎么配置python环境_idea怎么指定python运行路径_12


在命令行输入python

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_13


如果出现了python的版本那么就证明我们的python环境已经配置成功了

二、第一个Python程序

如何使用Python程序输入第一个Hello World!呢?

首先我们还是先打开命令窗口:

idea怎么指定python运行路径 idea怎么配置python环境_ide_14


当我们输入python后,出现了三个箭头后,我们就可以输入Python命令了

idea怎么指定python运行路径 idea怎么配置python环境_idea怎么指定python运行路径_15


大家可以发现我们的Python代码是非常简单的,如下:

print("Hello World!")

含义:向屏幕输出(显示),Hello World!
注意: 输入的双引号和括号,都必须使用英文符号

常见问题

问题1

我们再写代码时,如果出现:

idea怎么指定python运行路径 idea怎么配置python环境_python_16


python不是内部或外部命令,也不是可运行的程序或批处理文件

idea怎么指定python运行路径 idea怎么配置python环境_ide_17


这是因为大家在安装python的时候,没有勾选:Add python.exe to PATH,现在我们需要卸载Python,重新安装python,勾选这个选项

问题2

我们在命令行出现了:无法初始化设备PRN

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_18


这是因为我们没有进入到python解释器环境内执行代码

应该在命令提示符内:

1.先输入python,当屏幕上出现:>>>标记的时候

2.输入代码执行,才可以

问题3

执行出现:SyntaxError: invalid character ‘”’ (U+201D)

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_19


这是因为,我们的代码出现了中文符号,请检查代码中的:

双引号,小括号等

三、Python解释器

首先我们的计算机只认识二进制,也就是0和1,我们的Python解释器就是将我们的Python代码转换为二进制

idea怎么指定python运行路径 idea怎么配置python环境_python_20


我们安装Python环境的本质上,就是在电脑上安装Python解释器程序。代码我们随时都可以写,但是能不能运行就得看是否安装解释器程序了

我们的Python解释器存放在:<Python安装目录>/python.exe

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_21


我们在CMD(命令提示符)程序内,执行的python,就是上图的python.exe程序

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_22


大家先需要注意,我们在python解释器程序内,我们没写一行代码回车后就直接运行了,那么我们是否能写多行代码,然后一次性运行呢?

我们可以将代码写入一个以.py为结尾的文件中,然后使用python命令去运行它

idea怎么指定python运行路径 idea怎么配置python环境_ide_23


然后我们将文件后缀名改为.py

idea怎么指定python运行路径 idea怎么配置python环境_idea怎么指定python运行路径_24


然后我们在命令提示符程序内,使用python命令运行它:

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_25

四、PyCharm工具安装和配置

Python程序的开发有许多种方式,我们常见的有:
1.Python解释器环境内,执行单代码
2.使用Python解释器程序,执行Python代码文件
3.使用第三方IDEA(集成开发工具),如PyCharm软件,开发软件

安装

首先我们打开jetbrains官网:jetbrains.com

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_26


该网站支持中文,我们切换一下

idea怎么指定python运行路径 idea怎么配置python环境_python_27


我们选择开发者工具—>PyCharm

idea怎么指定python运行路径 idea怎么配置python环境_ide_28


然后往下面划

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_29


我们发现有两个版本,专业版(收费),社区版(免费),我们这里使用免费版即可

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_30

这里也可以选择不同的操作系统版本,我这里就选择windows版本

idea怎么指定python运行路径 idea怎么配置python环境_ide_31


然后双击exe文件

idea怎么指定python运行路径 idea怎么配置python环境_idea怎么指定python运行路径_32


自定义安装路径:

idea怎么指定python运行路径 idea怎么配置python环境_ide_33


idea怎么指定python运行路径 idea怎么配置python环境_开发语言_34


idea怎么指定python运行路径 idea怎么配置python环境_开发语言_35


然后我们选择运行

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_36

使用

新创建python项目

idea怎么指定python运行路径 idea怎么配置python环境_ide_37


idea怎么指定python运行路径 idea怎么配置python环境_idea怎么指定python运行路径_38


idea怎么指定python运行路径 idea怎么配置python环境_python_39


我们选择系统内置的解释器,也就是我们下载的解释器

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_40


然后创建即可:

idea怎么指定python运行路径 idea怎么配置python环境_python_41


默认会为我们创建一个main.py的文件:

idea怎么指定python运行路径 idea怎么配置python环境_python_42


我们来自己创建一个python文件:

idea怎么指定python运行路径 idea怎么配置python环境_ide_43


编辑好python代码后,右键run

idea怎么指定python运行路径 idea怎么配置python环境_ide_44

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_45


这就是PyCharm的一个简单使用了

PyCharm基本使用

修改主题

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_46


然后可以进行选择切换

idea怎么指定python运行路径 idea怎么配置python环境_python_47


修改默认字体和大小

打开设置:

idea怎么指定python运行路径 idea怎么配置python环境_pycharm_48


idea怎么指定python运行路径 idea怎么配置python环境_ide_49


但这样调节字体太过于麻烦,我们设置一下简单的方式:

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_50


我们选择鼠标滑动调节

idea怎么指定python运行路径 idea怎么配置python环境_idea怎么指定python运行路径_51


idea怎么指定python运行路径 idea怎么配置python环境_idea怎么指定python运行路径_52


我们调大字体和调小字体都进行设置,然后我们在PyCharm主页面就可以使用鼠标滑轮进行字体大小的调节了

汉化软件

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_53


idea怎么指定python运行路径 idea怎么配置python环境_pycharm_54


下载完成后,我们点击重启IDEA

idea怎么指定python运行路径 idea怎么配置python环境_python_55


idea怎么指定python运行路径 idea怎么配置python环境_ide_56

翻译软件

idea怎么指定python运行路径 idea怎么配置python环境_开发语言_57


idea怎么指定python运行路径 idea怎么配置python环境_idea怎么指定python运行路径_58


常用快捷键

idea怎么指定python运行路径 idea怎么配置python环境_python_59