1 安装
1.1 下载
首先,去官网下载PyCharm。
PyCharm可以在Windows,Mac和Linux系统上使用,并且有专业版和社区版之分。
专业版和社区版的定位和区别:
-
专业版:适用于科学和Web Python开发;具有HTML,JS和SQL支持;收费(当然也可以通过某种方式激活,有经济条件的还是支持一下好软件吧~)
-
社区版:适用于纯Python开发;免费,不需要激活,开箱即用
这里,根据我的需求,下载Linux系统上的社区版。
1.2 安装
解压下载的压缩包:
tar zxvf pycharm-community-2019.3.tar.gz
解压出文件夹pycharm-community-2019.1.3
,里面有文件Install-Linux-tar.txt
,内容如下:
PyCharm
INSTALLATION INSTRUCTIONS
Linux Installation Instructions
Unpack the PyCharm distribution archive that you downloaded to
where you wish to install the program. We will refer to this destination
location as your {installation home} below.Open a console and cd into “{installation home}/bin” and type:
./pycharm.sh
to start the application. As a side effect, this will initialize various
configuration files in the ~/.PyCharmCE2019.1 directory.[OPTIONAL] Add “{installation home}/bin” to your PATH environment
variable so that you may start PyCharm from any directory.[OPTIONAL] To adjust the value of the JVM heap size, create
~/.PyCharmCE2019.1/config/pycharm.vmoptions (or pycharm64.vmoptions
if using a 64-bit JDK), and set the -Xms and -Xmx parameters. To see how
to do this, you can reference the vmoptions file under
“{installation home}/bin” as a model.[OPTIONAL] Changing the location of “config” and “system”
directories
------------------------------------------------------------------------------ By default, PyCharm stores all your settings under the
~/.PyCharmCE2019.1/config directory and uses
~/.PyCharmCE2019.1/system as a data cache. If you want to change
these settings,
Open a console and cd into ~/.PyCharmCE2019.1/config
Create the file “idea.properties” and open it in an editor. Set the
idea.system.path and/or idea.config.path variables as desired, for
example:idea.system.path=~/custom/system
idea.config.path=~/custom/configNote that we recommend to store data cache (“system” directory) on a disk
with at least 1GB of free space.Enjoy!
-PyCharm Development Team
很明显,这是官方的安装教程,我们按照它来安装PyCharm。
cd ~/pycharm-community-2019.1.3/bin
./pycharm.sh
然后,会打开PyCharm,表明安装成功。
Install-Linux-tar.txt
中还有一些可选的操作,比如更改环境变量,系统设置和数据缓存的路径,一般保持默认即可。
页面还有以下内容:
意思是PyCharm也可以作为快照包提供。如果你使用的是Ubuntu 16.04或更高版本,则可以用以下命令行安装PyCharm:
sudo snap install [pycharm-professional|pycharm-community] --classic
注:我没有试过这种方式,因为刚发现。。。
2 配置
2.1 导入Color Scheme
PyCharm默认的主题比较丑,看代码体验不好,最好自己导入Color Scheme。
1.导入Color Scheme:
下载Color Scheme,然后加载其在硬盘上的路径:
2.使用Ctrl+鼠标滚轮调整字体大小:
3.如果觉得导入的Color Scheme的字体不合适,可以在Size中调整:
2.2 添加桌面快捷键
如果不想每次都通过终端运行命令启动PyCharm,那就需要添加桌面快捷方式。
新建文件pycharm.desktop
:
touch ~/pycharm.desktop
打开文件pycharm.desktop
,编辑以下内容:
[Desktop Entry]
Type=Application
Name=Pycharm
GenericName=Pycharm3
Comment=Pycharm3:The Python IDE
Exec=bash -i -c "~/pycharm-community-2019.1.3/bin/pycharm.sh"%f
Icon=/home/pan/下载/pycharm-2017.3.1/bin/pycharm.png
Terminal=pycharm
Categories=Pycharm
注意:bash -i -c
用于从文件~/.bashrc
中加载系统环境变量,比如要想使用PyCharm开发ROS,就必须加上这个。
将文件pycharm.desktop
移动到/usr/share/applications/
:
sudo mv pycharm.desktop /usr/share/applications/
2.3 PEP8代码规范
Python具有PEP8代码规范,PyCharm严格遵守这个规范,有不符合的就会在下面显示波浪线,数量多了会很难受。
主要是要注意空格,缩进和换行等问题。
虽然可以忽略错误提示,但是最好遵守PEP8代码规范,这样会使代码更加清晰易读,不容易出错。
PEP8代码规范的内容可以参考文章,这里不再赘述。