我试图在 ubuntu 3.10.4LTS 上的 gedit 14.04 中添加一些插件,当我尝试在 gedit 中激活这些插件时发生了一些错误:
(gedit:20686): libpeas-警告 **:初始化 Python 插件加载器时出错:PyGObject 初始化失败 ImportError: 無法輸入 gobject(錯誤為: ImportError("沒有名為 'gi'' 的模組",))
(gedit:20686): libpeas-WARNING **: 请检查libpeas所需的所有Python相关软件包的安装情况,然后重试
(gedit:20686): libpeas-WARNING **:加载器'python3'不是有效的PeasPluginLoader实例
(gedit:20686): libpeas-警告 **:找不到插件"bracket完成"的加载器"python3"
我明白了,在格德
未找到插件加载器"python3"
有没有人知道问题可能来自哪里?
我在使用不同的插件 (reST) 时遇到了同样的错误。导致错误的问题是,当虚拟环境处于活动状态时,我从命令行运行了它。出于这个原因,Python3没有使用(和找到)系统库。
解决方案:我只是从 GUI 正常运行 gedit(或者在终端中停用 virtualenv 之后),编辑器和插件刚刚加载正常。仔细检查您是否有类似原因。
否则,您可能真的必须检查错误消息的内容:是否安装了所有"libpeas 所需的相关软件包"。请参阅适用于 Trusty 的软件包 libpeas-1.0-0 的详细信息。
补充@Railslide的答案:
-
在您的
/usr/lib/gedit/plugin
中搜索您的插件文件(例如bracketcompletion.plugin
),并将Loader=python3
更改为Loader=python
-
如果这仍然返回错误 - 可能是因为它与语法不匹配
python3
: 使用命令2to3
如下所示:cd python_directory/ sudo 2to3 -f all -w *
例如,对于gedit-latex-plugin
...
cd /usr/lib/gedit/plugins/
sudo sed -i 's/python/python3/g' latex.plugin # only if you haven't already replaced python->python3
cd latex/
sudo 2to3 -f all -w *
然后,这将通过将python2.x
代码替换为python3
代码来修复插件
相关
- 激活 gedit-latex-plugin 在 Vivid 中失败
- Gedit 3.8.3 仅支持 python3 插件
gedit 错误,请参阅 https://bugs.launchpad.net/ubuntu/+source/gedit/+bug/859089
作为一种解决方法,在您的/usr/lib/gedit/plugin
中搜索您的插件文件(例如 bracketcompletion.plugin
),并将Loader=python3
更改为Loader=python
不幸的是,此解决方法不适用于所有插件。
我今天遇到了基本相同的问题,尽管使用代码注释插件。就我而言,该问题仅在从命令行执行 gedit 时才出现,类似于@Peterino(尽管实际上没有明确设置虚拟环境)。否则一切都很好。
发生这种情况的原因似乎与以下事实有关:我在.bashrc
中设置了我的$PATH
,python3
对应于当地的anaconda/miniconda装置。一个不需要的副作用是,当从终端启动时,gedit
实际上会选择本地miniconda安装而不是/usr/bin/python3.X
。(通过暂时将miniconda文件夹移动到其他地方或以其他用户身份登录来检查)。
可能的修复
(虽然我仍然对他们中的任何一个都不完全满意)。
把它放在 .bashrc 中是有效的:
export CONDAPATH=$HOME/miniconda3/bin
export PATH="$CONDAPATH:$PATH"
# ^ put these two lines instead of the original miniconda export.
# __ : naming convention for private functions
__geditfix() {
export PATH=$(echo $PATH | sed -E "s|:$CONDAPATH|$CONDAPATH:||g"); # remove conda from the PATH environment variable, using RegEx
gedit "$@"; # call gedit, giving it all arguments
export PATH="$CONDAPATH:$PATH"; # add conda to the PATH environment variable
} # Using a function rather than an alias, so that the filename is given to gedit, as it should and not to setconda().
alias gedit='__geditfix' # So that we can run our fix simply via: gedit <arguments>.
这个 ^ 所做的是为 gedit 创建一个别名,使用一个实际上
- 1)从
$PATH
中删除~/miniconda3/bin
, - 2)运行gedit(
/usr/bin/gedit
),给出所有参数, - 3)把
~/miniconda3/bin
放回我们的$PATH
。
有了这几行.bashrc
,就可以简单地称之为gedit <arguments>
- 插件工作,因为 gedit 将从
/usr/bin/
中挑选python
, - 来自miniconda的
python
,jupyter-notebook
,conda
等仍然可以毫无问题地直接访问
。
顺便说一句,这有助于:https://stackoverflow.com/a/23134318/452522(SED中的环境变量替换)
替代解决方案:安装此 v:
conda install -c conda-forge pygobject
从终端输出中可以猜到,在使用miniconda python3安装时,它丢失了。