我正在使用一个名为VMTK的模块来构建分析血管模型的脚本。他们有编写这些脚本的教程。,因此系统可以很容易地识别它们,从而允许您将脚本连接到一起称为PypeS。我完全按照所示的方式学习了教程,并得到了相同的"No模块名: vmtk.name_of_script“错误。
我试过的是:
__init__.py能够捕获它本教程说,您可以将自定义脚本放在文件系统的任何位置,但无论如何都会出现问题。我目前正在通过Anaconda使用Python3.6.10,并在MacOS High上安装VMTK (而不是从源代码构建)。
我真的不想要从源代码构建,因为我只需要预加载脚本和编写新脚本的能力,而不是使用构建脚本的C++文件。我被困了这么久,根本不知道是什么问题。我发现最接近这个问题的是一个解决这个问题的问题,但OP只是说问题已经解决了,没有提供其他信息。
下面是前面提到的代码:
#!/usr/bin/env python
import sys
from vmtk import pypes
from vmtk import vmtkscripts
customscript = 'customScript'
class customScript(pypes.pypeScript):
def __init__(self):
pypes.pypeScript.__init__(self)
def Execute(self):
pass
if __name__=='__main__':
main = pypes.pypeMain()
main.Arguments = sys.argv
main.Execute()根据本教程,我还运行了chmod u+x customscript.py来更改我的文件的权限,以便我可以执行它。我被困在脚本应该在VMTK中执行最基本的操作的地方。有什么想法吗?
编辑:这是确切的错误:
$ ./customscript.py
No module named 'vmtk.customscript'
Traceback (most recent call last):
File "/vmtk/lib/python3.6/site-packages/vmtk/pype.py", line 290, in Execute
module = importlib.import_module('vmtk.'+scriptName)
File "/vmtk/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'vmtk.customscript'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./customscript.py", line 21, in <module>
main.Execute()
File "/vmtk/lib/python3.6/site-packages/vmtk/pypescript.py", line 688, in Execute
pipe.Execute()
File "/vmtk/lib/python3.6/site-packages/vmtk/pype.py", line 298, in Execute
self.PrintError(str(e))
File "/vmtk/lib/python3.6/site-packages/vmtk/pype.py", line 102, in PrintError
raise RuntimeError(errorMessage)
RuntimeError: No module named 'vmtk.customscript'我想追溯这个问题,但我不认为编辑任何预加载的文件是必要的。
发布于 2020-07-29 02:50:36
经过一周的尝试和探索,我找到了一个解决方案:
- If you don't have cmake installed on your computer, they offer a GUI version on their website. I'm not sure how it would work for Windows, but it definitely works for Mac.source vmtk_env.sh的每个VMTK终端实例。这将允许您使用VMTK环境。chmod u+x name_of_script.py (如果您是在基于Unix的操作系统中)。这将允许您使用./name_of_script.py执行该文件。tkinter,另一个用于joblib。- The `tkinter` issue is one that can be resolved by going into the file where the import is, I believe `vmtkscripts.py`, and changing all instances of `tkinter` to `Tkinter` (capital T). This is because they changed the name of the module from Python 2 to 3, so in newer versions of Python it would be `tkinter`. That fixed the first error.- When I attempted to fix the `joblib` issue, I saw that the other version of Python available on my system already had it, thus I couldn't install it through pip. Instead, you can do `python-2.7 -m pip install joblib` to install it for a specific version of Python. Although I did uninstall `joblib` as a whole from my computer before doing that.一切都会好起来的。下一次我尝试运行我的脚本时,它运行时没有任何错误。
额外:我没有为此使用任何Anaconda环境。可能会回去试着安排,但我很高兴我已经开始工作了。此外,我还从我的计算机中删除了VMTK的二进制安装。如果你只想从源头构建它,就不需要把它放在身边。通过运行source vmtk_env.sh命令,可以在设置vmtk后通过终端运行VMTK。
https://stackoverflow.com/questions/63044473
复制相似问题