我最近从 2.8 更新到 2.10 GIMP,似乎我的导入自定义(相对)*.py 文件的插件都不再工作了。我剖析了代码,它不是“path_tools.py”文件的内容,它只是尝试导入自定义模块的行为(即使它是一个空文件,它仍然无法工作)。如果没有这行代码,它就可以很好地显示在 GIMP 中:
from path_tools import *
插件和path_tools.py都在同一个文件夹里
\AppData\Roaming\GIMP\2.10\插件
我尝试通过添加句点来使用显式相对
from .path_tools import *
from ..path_tools import *
from ...path_tools import *
etc.
我尝试通过在文件底部添加一个空的 GIMP 效果将文件变成一个插件,以查看 GIMP 是否只是以某种方式忽略了我的文件
def path_tools(img, drw):
return
register(
"python-fu-path-tools",
"Path Tools",
"",
[...]
然后在命令提示符下打开 GIMP
"c:\program files\gimp 2\bin\gimp-2.10" --verbose --console-messages
对于每个无法加载的插件,它只会给我一堆这样的消息:
Querying plug-in: 'C:\Users\ \AppData\Roaming\GIMP\2.10\plug-ins\path_tools.py'
c:\program files\gimp 2\bin\gimp-2.10: LibGimpBase-WARNING: gimp-2.10: gimp_wire_read(): error
但那些看起来像是警告,特别是因为另一个插件不会加载的实际错误,我猜出于类似的原因:
GIMP-Error: Unable to run plug-in "export-ALL.py"
是否与顶部的这些警告有关?
Parsing 'c:\program files\gimp 2\lib\gimp\2.0\interpreters\pygimp.interp'
GIMP-Warning: Bad interpreter referenced in interpreter file c:\program files\gimp 2\lib\gimp\2.0\interpreters\pygimp.interp: python
GIMP-Warning: Bad binary format string in interpreter file c:\program files\gimp 2\lib\gimp\2.0\interpreters\pygimp.interp
我只是不知道发生了什么,也不知道该怎么办。是否有一个目录可以将文件放入插件可见的目录?因为它确实可以导入像“sys”、“os”这样的常规模块。
(抱歉,如果这是一个非常愚蠢的问题,我只将 Python 用于 GIMP 插件。)
请您参考如下方法:
似乎嵌入 Gimp 2.10 的 Python 解释器使用 / 作为路径分隔符,而 Gimp 2.10 在 Windows 上使用 \。
讨论的问题here .
使用以下内容创建名为 C:\Program Files\GIMP 2\32\lib\python2.7\sitecustomize.py 的文件似乎可以解决问题。
import sys
class Issue1542:
def __del__ (self):
if len (sys.argv[0]):
from os.path import dirname
sys.path[0:0] = [dirname (sys.argv[0])]
sys.argv = Issue1542 ()
