【转载】geany linux python编译器 开源

http://www.dekiru.cn/?p=1491

Geany 不好用,建议用一些好用的编辑器或ide

Subliem Text 或 VS code

Pycharm等。

菜单栏–生成–设置生成命令–执行命令(execute)那里输入python3 %f

以后直接按F5键即可运行python文件.

设置代码检查

配置pep8

菜单栏–生成–设置生成命令–Lint–输入pep8 –max-line-length=80 "%f"

sudo pip3 install pep8

或者使用最新的pycodestyle进行代码检测.

sudo pip3 install pycodestyle

使用pep8

菜单栏–生成–Lint

使用空格代替制表符

菜单栏–编辑–首选项–编辑器–缩进–宽度:4,类型:空格,勾上"用Tab键缩进"

菜单栏–编辑–首选项–文件–保存文件–用空格替换制表符

代码格式化

使用black或着autopep8.

配置black或autopep8

sudo pip3 install black

sudo pip3 install autopep8

菜单栏–生成–设置生成命令–python命令部分–新增命令项:格式化python文件,black %f

菜单栏–生成–设置生成命令–python命令部分–新增命令项:格式化python文件,autopep8 -i %f

black使用方法

菜单栏–生成–格式化python文件,或者直接按F9格式化.

然后ctrl+r重新载入格式化的文件即可.

自动完成

配置snippets

菜单栏–工具–配置文件–snippets.conf,或者直接修改 ~/.config/geany/snippets.conf

官网来源https://wiki.geany.org/snippets/python/start

[Special]部分新增

wordchars=._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

[Python]部分新增

for=for i in xrange(%cursor%):\n\t

doc=""" %cursor% """\n

elif=elif %cursor%:\n\t

else=else:\n\t%cursor%

if=if %cursor%:\n\t

from=from %cursor% import \n

main=if __name__ == '__main__':\n\t%cursor%

class=class %cursor%(object):\n\t""" Class doc """\n\t\n\tdef __init__ (self):\n\t\t""" Class initialiser """\n\t\tpass

def=def %cursor%(self):\n\t""" Function doc\n\n\t@param PARAM: DESCRIPTION\n\t@return RETURN: DESCRIPTION\n\t"""\n\t

get=def get%cursor%(self): return self._var\n

set=def set%cursor%(self): self._var = var\n

.=self.%cursor%

prop=property %cursor%:\n\tdef __get__(self):\n\t\treturn self.%cursor%_get()\n\n\tdef __set__(self, value):\n\t\tself.%cursor%_set(value)

try=try:\n\t%cursor%\nexcept Exception, e:\n\t

py=#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n%cursor%

while=while %cursor%:\n\t

with=with %cursor%:\n\t

head="""\n\t%cursor%PROJECT – MODULE\n\n\tDESCRIPTION\n\n\t@copyright: {year} by {developer} <{mail}>\n\t@license: GNU GPL, see COPYING for details.\n"""\n

pp=from pprint import pprint\npprint(%cursor%)

cod=# coding: utf-8

dt=from datetime import datetime

使用方法,输入main,按tab,geany自动将main补全为if __name__ == '__main__':

代码提示

配置tag

官网下载tag文件https://wiki.geany.org/tags/start

解压后,把tag后缀的文件方法到~/.config/geany/tag目录即可

安装插件

配置插件:菜单栏–工具–插件管理器–勾选插件–点击窗口低下的配置按钮

官网地址:https://plugins.geany.org/

文件浏览器:sudo apt-get install geany-plugin-treebrowser

成对标签高亮:geany-plugin-pairtaghighlighter

自动高亮相同的字符:geany-plugin-automark

代码缩略图:geany-plugin-overview

虚拟终端支持:geany-plugin-multiterm

markdown支持:geany-plugin-markdown

python支持:geany-plugin-py(Provides most of the standard Geany C API for Python,该插件可以让geany支持python写的插件,比如geany pynav,也可以自己用python为geany写插件.)

xml美化:geany-plugin-prettyprinter

在实现和接口间跳转:geany-plugin-codenav

其他的小附加组件:geany-plugin-addons

在终端执行程序

菜单栏–编辑–首选项–虚拟终端–勾选“在虚拟终端中执行程序”

geany的插件文档

https://www.geany.org/manual/reference/index.html

配置pip国内的一些镜像

  阿里云 https://mirrors.aliyun.com/pypi/simple/

  中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

  豆瓣(douban) http://pypi.douban.com/simple/

  清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

  中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

~/.pip/pip.conf

[global]

index-url = https://pypi.tuna.tsinghua.edu.cn/simple