1
我曾与Qtdesingner, 在UI蟒蛇做了玛雅项目经理,一个QLineEdit的授权用户填写的脚本的路径运行(变量是:BatchRunScript
) 但似乎不可能导入模块,如果它是一个变量(str
):
import maya.utils
BatchRunScript = 'X:\PathOfTheScript\NameOfScriptToRun.ScriptToRun()'
BatchRunScriptName = BatchRunScript.replace('\\', '/').split('/')[-1]
BatchRunScriptPath = BatchRunScript.replace('\\', '/').split(BatchRunScriptName)[0]
BatchRunModuleName = BatchRunScriptName.split('.')[0]
print 'BatchRunScriptPath: ', BatchRunScriptPath # X:/PathOfTheScript/
print 'BatchRunScriptName: ', BatchRunScriptName # NameOfScriptToRun.ScriptToRun()
print 'BatchRunModuleName: ', BatchRunModuleName # NameOfScriptToRun
sys.path.append(BatchRunScriptPath)
import BatchRunModuleName
maya.utils.executeDeferred(BatchRunScriptName)
它给我这个错误:
Error: ImportError: file <maya console> line 13: No module named BatchRunModuleName
有另一种方式来d从另一个内部运行一个python脚本?
你不应该硬编码''Python''这样的,因为它可能是不正确的。更好的做法是使用['sys.executable'(https://docs.python.org/3/library/sys.html#sys.executable),这将永远是正确的。 – martineau
非常感谢您的回答:) – Gnn