![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-422123902a95c1ca.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
搭建环境
1、win10_X64,其他Win版本也可以。
2、PyCharm版本:Professional-2016.2.3。
搭建准备
1、到PyCharm官网下载PyCharm安装包。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-af5f47123462aa88.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
2、选择Windows系统的专业版下载。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-d1c6c9303ad5b2c2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
3、下载好的安装包。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-b24a4b04f3142d76.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
安装软件
1、双击安装包进行安装。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-a3294346b4102626.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/502)
2、自定义软件安装路径(建议路径中不要中文字符)。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-473fe858918d46da.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/499)
3、创建桌面快捷方式并关联*.py文件。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-0dc8a3e19e8ac295.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/497)
4、选择开始菜单文件夹(默认即可),点击安装。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-ec05d51d8c387922.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/496)
5、耐心等待安装。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-4c047b85f0c17ffe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/497)
6、安装完成,勾选立即运行PyCharm。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-ae2d233d08abc9bb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/497)
7、选择是否导入开发环境配置文件,我们选择不导入。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-005719e55dd709b9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/539)
8、阅读协议并同意(少年,选择略过吧)。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-1fa983d52b8106fd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/495)
9、修改hosts文件:C:\Windows\System32\drivers\etc\hosts
;
0.0.0.0 account.jetbrains.com
10、选择输入激活码激活软件(请阅读下一步获取激活码)。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-53453ffc2ec1df04.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/413)
11、软件激活方式
??1、推荐购买正版软件。
??2、可以选择下载社区版本,免费的。
??3、专业版本可以选择试用,免费试用30天。
??4、网上寻找激活码或授权服务器。
我们使用第4种方法:
??在IntelliJ IDEA 注册码网站,获取激活码,以前允许自定义用户名,现在已经是No了,只能直接获取激活码。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-ca8574ba996fff32.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
点击获取激活码后,文本默认是全选中的,直接右击选择复制即可。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-60cc9e5bd32f1475.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
12、将激活码粘贴到文本框,点击OK即可。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-8af69f786fe4ccb1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/414)
13、PyCharm的欢迎界面。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-18de2e0daaa49f4a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/641)
14、选择IDE主题与编辑区主题,建议Darcula主题(温馨提示:黑色更有利于保护眼睛噢!!!)。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-f0b7599e834fa79b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/660)
15、由于我们更改主题,故会提示重启IDE,选择Yes。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-2842d3a880be0f41.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/660)
16、选择创建新项目。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-339c8a1fb47ee99c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/663)
17、自定义项目存储路径,IDE默认会关联Python解释器。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-3f2c4845eb472943.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/662)
18、IDE提供的提示,我选择在启动时不显示提示。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-f7d733ed911cf04a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/571)
19、如何在Linux
上安装PyCharm
,请参阅我的博客。
编程字体
编程最常见的是什么?(肯定不是Bug),而是代码了,绝大部分人都一直使用编辑器默认的字体,其实,换一套适合自己的编程字体不仅能让代码看得更舒服,甚至还能提高工作效率的!
那么如何选择编程字体呢?What!!!
??1、等宽字体。
??2、有辨识度,即0与O,1与l的区别。
推荐一款编程字体Hack,进入Hack官网,点击Download。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-64784c703d148216.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/482)
选择适合Windows系统的软件包下载。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-0e3f8555fa15c875.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/613)
进入GitHub下载安装程序。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-687c597d2d2348c6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
下载完成的安装包,双击安装即可。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-63b61c7ef65efee9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/590)
配置IDE
1、显示/隐藏功能侧边栏(软件的左下角)。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-04f1ca2b2278333e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
2、显示项目目录结构。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-0fe5643b3734ac94.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/303)
3、配置IDE,按照下图,进入Settings。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-d5290f61a0566035.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/493)
4、设置显示行号,显示空白字符。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-8854ff179c7689bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/618)
5、设置编程字体为Hack,字体大小为15。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-8388418eb881a52a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
6、设置控制台字体为Hack,字体大小为15。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-03a6980f6073bfff.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
7、修改新建*.py文件的模版,首行添加默认解释器(方便在Linux运行),添加文件编码。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-f694f77a76289ad4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
8、设置Python默认解释器,添加额外的扩展包,
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-26a09e44bc15699c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
常用快捷键
1、Ctrl + Enter:在下方新建行但不移动光标;
2、Shift + Enter:在下方新建行并移到新行行首;
3、Ctrl + /:注释(取消注释)选择的行;
4、Ctrl + Alt + L:格式化代码(与QQ锁定热键冲突,关闭QQ的热键);
5、Ctrl + Shift + +:展开所有的代码块;
6、Ctrl + Shift + -:收缩所有的代码块;
7、Ctrl + Alt + I:自动缩进行;
8、Alt + Enter:优化代码,添加包;
9、Ctrl + Shift + F:高级查找;
10、Alt + Shift + Q:更新代码到远程服务器;
远程连接编程
有时我们需要在Windows上编写代码,在Linux运行代码,或着是团队合作开发项目,我们就需要远程连接Linux服务器进行编程。
??在这里我使用虚拟机假装远程服务器(尴尬),虚拟机IP地址:192.168.10.50,使用XShell(ssh协议)连接服务器(虚拟机),使用PyCharm(sftp协议)连接服务器(虚拟机)。
1、在XShell上查看虚拟机IP地址。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-6527776403df29e3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/563)
2、在虚拟机上创建项目工作空间。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-35daec61a17a2b81.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/472)
3、在PyCharm上配置远程服务器。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-5d050434ce1c14f6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/654)
4、添加新连接。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-28ba6e0111ad5b9c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
5、设置连接名称及使用的协议类型。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-93ec4423df36e08b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/397)
6、设置主机IP地址,工作空间(之前已创建),登录信息。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-a285d4137ec6cef0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
7、浏览远程服务器。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-25bb77d93a21d617.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/667)
8、在服务器上新建文件。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-604e00aec8524754.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/381)
9、编写代码。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-3ecb4cbc3dba08a7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/603)
10、点击编辑区右上角更新代码到服务器。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-3840662230e80217.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/665)
11、设置文件的权限,添加执行权限。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-9aded07b44eb04cb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/262)
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-a6a3f67a0dc97727.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/241)
12、使用XShell执行脚本文件。
![技术分享图片](http://upload-images.jianshu.io/upload_images/1152061-8a872858d1e0f8ca.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/453)
接下来,让我们一起去享受Python的简单、优雅之美吧。
作者:Ben_王宇霄
链接:https://www.jianshu.com/p/042324342bf4
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。