Ubuntu 22.04下Global Gtags无法生成及查找Python标签的问题求助
我目前使用的是Ubuntu 22.04系统,已经安装了global包,系统自带的/etc/gtags/gtags.conf配置文件里,已经预设了pygments-parser的相关配置,具体内容如下:
# # Plug-in parser to use Pygments. # pygments-parser|Pygments plug-in parser:\ :tc=common:\ :ctagscom=/usr/bin/ctags-exuberant:\ :pygmentslib=$libdir/gtags/pygments-parser.la:\ :langmap=ABAP\:.abap:\ :langmap=ANTLR\:.G.g:\ :langmap=ActionScript3\:.as:\ :langmap=Ada\:.adb.ads.ada:\ :langmap=Python\:.py.pyw.sc.tac.sage:\
为了验证pygments-parser是否能正常解析Python代码,我做了一组简单的测试,步骤如下:
- 先创建一个测试用的Python文件
test.py:
#!/usr/bin//python def message(): print("Hello World") if __name__ == "__main__": message()
- 执行gtags命令生成标签文件:
/tmp/tmp$ gtags --gtagslabel pygments-parser -v . [Tue Aug 19 17:57:33 CST 2025] Gtags started. Using configuration file '/etc/gtags/gtags.conf'. Using configuration label 'pygments-parser'. Using plug-in parser. [Tue Aug 19 17:57:33 CST 2025] Creating 'GTAGS' and 'GRTAGS'. [1] extracting tags of test.py [Tue Aug 19 17:57:33 CST 2025] Creating indexes for idutils. mkid: nothing to do [Tue Aug 19 17:57:33 CST 2025] Done.
- 尝试用global查找定义的
message函数:
tmp/tmp$ global -v -x message test.py object not found (using '/tmp/tmp/GTAGS').
另外我检查了系统中ctags的路径:
/tmp/tmp$ which ctags /usr/bin/ctags
从结果来看,gtags虽然显示成功执行,但并没有正确生成Python函数的标签,导致global无法找到目标函数。有没有朋友遇到过类似的问题?或者能帮我分析下可能的原因和解决方向吗?
内容来源于stack exchange
相关产品推荐
相关产品推荐

