![](/img/trans.png)
[英]my python code doesn't get executed. No error, no process finished text just blank. Other codes works fine
[英]“process.currentDirectoryPath()” function is not changing the path and my python file doesn't get executed through swift code
我正在研究一种在Xcode中的MacOS应用程序中通过swift执行python脚本的方法。 我正在使用Process类来执行python脚本。 因此,当我尝试使用process.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
这是我得到的输出。 谁能帮我。
两个问题。 第一:
process.currentDirectoryPath = "\\(NSHomeDirectory())/Downloads/<pyhton-file>"
必须将当前目录路径设置为目录,而不是文件路径。
第二:
process.arguments = ["recognize_video.py --detector face_detection_model ..."]
参数必须作为单独的数组元素传递:
process.arguments = ["recognize_video.py", "--detector", "face_detection_model", ... ]
与shell(执行在终端中键入的命令)不同, Process
在将参数传递给要执行的进程之前不会将参数分开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.