Maya如何使用多个文件创建python脚本?

2024-06-25 22:45:04 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我在这里的第一篇文章,请理解我是一个初学者,我正在学习“在职”。在

有人能解释一下如何在Maya python脚本中从不同的模块导入文件吗?我得到以下错误:

Error: ImportError: file E:/.../bin/mainScript.py line 17: No module named tools

以下是我的目录和代码:

^{pr2}$

我正试图导入tools.pymainScript.py

编辑:

好吧,因为它不适合发表评论,所以我编辑这篇文章以增加准确性。我移动了桌面上的“主文件夹”,并在Maya中再次运行脚本。它仍然不起作用,但我有一个更完整的错误回溯。这里是:

# Error: Error in  maya.utils._guiExceptHook:
#   File "C:\Program Files\Autodesk\Maya2014\Python\lib\site-packages\maya\utils.py", line 332, in formatGuiException
#     result = u'%s: file %s line %s: %s' % (exceptionType.__name__, file, line, exceptionMsg)
# UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 11: ordinal not in range(128)
# 
# Original exception was:
# Traceback (most recent call last):
#   File "<maya console>", line 3, in <module>
#   File "C:/Users/UKDP/Desktop/Main_folder/bin/mainScript.py", line 17, in <module>
#     from tools import ClassTest
# ImportError: No module named tools # 

Tags: inpy脚本bin错误lineerrortools
3条回答

您需要确保所有可导入的模块都在python路径上。在

如果您的文件在E:/main_folder中,则需要执行以下操作

import sys
sys.path.append("E:/main_folder")
import bin.tools
import bin.mainScript

等等。设置它的方式(使用“bin/\uu init_uy.py”)告诉python该模块名为bin,它有名为“mainScript”和“tools”的子模块。长时间讨论here

试试这个

我在桌面上有一个文件夹,这个文件夹名为Combo,有一个名为组合框.py下面是我如何访问它:

import sys #imports system's directory module
sys.path.insert(0,"C:/Users/dharmin.doshi/Desktop") #Add your directory, do not add your folder in the path unless the script is inside of folder inside of folder. Path needs to be in quotes and 0 is added as needed by the argument.
from Combo(Folder name) import combo (my python script)
reload (combo) #Optional to reload it every time you make changes to the script.
combo.run() #Call the function that runs the code. 

如果你需要工具.py那么你的道路将会是:

^{pr2}$

希望这有帮助:)

尝试导入如下内容:

>>>import san.libs.stringops

Where the san is dir(in san create __init__.py)
libs is a dir(in libs create __init__.py) 
and stringops.py is imported 

相关问题 更多 >