"进程.currentDirectoryPath()“函数没有改变路径,我的python文件没有通过swift cod执行

2024-09-28 22:18:41 发布

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

我正在研究一种通过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

这是我得到的结果。 有人能帮我吗。你知道吗


Tags: 文件le脚本outputmodel进程usrlocal
1条回答
网友
1楼 · 发布于 2024-09-28 22:18:41

两个问题。首先:

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在将参数传递给要执行的进程之前,不会将参数分开。你知道吗

相关问题 更多 >