我正在研究一种通过swift在Xcode的MacOS应用程序中执行python脚本的方法。我使用一个进程类来执行python脚本。所以当我尝试使用进程.currentDirectoryPath()将其指向系统中的python文件。 但我无法更改它,因为它在命令模块中抛出了一个错误,即找不到python文件
let process = Process()
process.launchPath = "/usr/local/bin/python"
process.currentDirectoryPath = "\(NSHomeDirectory())/Downloads/<pyhton-file>"
process.arguments = ["recognize_video.py --detector face_detection_model --embedding-model openface_nn4.small2.v1.t7 --recognizer output/recognizer.pickle --le output/le.pickle"]
do {
try process.run()
}
catch let error{
print(error.localizedDescription)
}
/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'recognize_video.py --detector face_detection_model --embedding-model openface_nn4.small2.v1.t7 --recognizer output/recognizer.pickle --le output/le.pickle': [Errno 2] No such file or directory
这是我得到的结果。 有人能帮我吗。你知道吗
两个问题。首先:
当前目录路径必须设置为目录,而不是文件路径。你知道吗
第二:
参数必须作为单独的数组元素传递:
与shell(执行您在终端中键入的命令)不同,
Process
在将参数传递给要执行的进程之前,不会将参数分开。你知道吗相关问题 更多 >
编程相关推荐