Python的环境搭建是Python学习的第一步,关于这一点,网上有很多的资源,方法五花八门。由于工作原因,自己给同事写过很多处理Excel、爬虫的代码,也装过很多次 Python(用 pyinstaller 打包成 exe 有时候太大了),所以决定写一篇以供初学者参考
Python环境搭建
直接安装 Anaconda (500M+)就行了 (嫌大的可以装 Miniconda,70M左右)
Anaconda 是什么?
Anaconda 是 Python 的一个发行版,集合了 jupyter notebook,pip,ipython ......反正对于新手来说不需要明白这些东西,装就完事了


这里两项都要勾选,别被红字吓到了,勾选了之后就不用手动添加到系统环境变量(对于新手来说,减少阻力,麻烦的事咱们不搞)
完成之后,我们打开【运行】(win+r )

输入cmd,确定,进入命令行,输入 python,然后回车

出现了 Python 字样,光标前面变成 >>> ,证明我们的电脑已经配置好了 Python 语言
sublime text 3 配置
安装没什么说的,官网下载安装就行了,下面说配置
打开刚安装好的 sublime text 3,选择编译环境

然后输入
print("我好了")
现在运行是没有效果的,因为还没有保存为py文件,ctrl+s 保存为一个以 .py 为后缀的文件

然后回到主界面,ctrl+b运行

中文成功输出,证明配置好了,但我们还需要按一个插件来支持 input
Ctrl + Shift + P,调出控制面板

输入 Install,按回车选择第一个

左下角显示读取中,有个等号在晃来晃去(可能需要科学上网)

读取成功后会弹出可供安装插件的列表

安装 SublimeREPL,使 Sublime支持 input
回车确认,左下角可以看到,安装中的提示

Ctrl + ` (esc下面的键)可以调出控制台,看后台运行情况,再按一次或者按 ESC 可以关闭
安装好之后,我们试着来调用它:
word = input('人类的本质就是复读机,说点什么吧:\n')
while True:
print(word)
word = input('')
跟 Ctrl+B 直接编译不同,利用插件来编译需要我们先手动 Ctrl+S 保存
常规调用:

当然,每次这样子拿鼠标选的话真的很麻烦,所以我们设置一个快捷键来实现同样的功能

左边是系统默认设置,我们在右边窗口输入以下设置(另一个 Alt + End 是终止编译的快捷键),Ctrl+S 保存

[
{
"keys": ["f4"],
"caption": "SublimeREPL: Python - RUN current file",
"command": "run_existing_window_command",
"args": {
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"}
},
{ "keys": ["alt+end"], "command": "exec", "args": {"kill": true} }
]
这时候我们按 F4 (记得先保存 py 文件 ),会新建一个标签页运行

这样不方便切换,所以我们打开两个视图

这样就可以左右相互对照着看了

另外设置一下缩进,把 Tab 统一换成 四个空格 (因为有的电脑按 Tab 是一条横线)


在右侧输入以下内容:
{
"font_size": 15,
"ignored_packages":
[
"Vintage"
],
"tab_size": 4,
"translate_tabs_to_spaces": true
}
对Python感兴趣或者是正在学习的小伙伴,可以加入我们的Python学习扣qun:784758214,看看前辈们是如何学习的!从基础的python脚本到web开发、爬虫、django、数据挖掘等,零基础到项目实战的资料都有整理。送给每一位python的小伙伴!分享一些学习的方法和需要注意的小细节,教你如何实现边学习边用Python赚钱的学习方式。点击加入我们的 python学习者聚集地
网友评论