python - 我需要通过 macOS 应用程序中的 NSTask 执行 python 脚本,但如果应用程序被沙盒化,则脚本无法找到模块。有什么建议吗?
问题描述
我想通过 macOS 应用程序中的 NSTask 执行 python 脚本。我的代码如下:
NSString *image1Path = [[NSBundle mainBundle] pathForResource:@"a1" ofType:@"jpg"];
NSString *image2Path = [[NSBundle mainBundle] pathForResource:@"a2" ofType:@"jpg"];
NSString *predictorPath = [[NSBundle mainBundle] pathForResource:@"shape_predictor_68_face_landmarks" ofType:@"dat"];
NSString *pythonScriptPath = [[NSBundle mainBundle] pathForResource:@"faceMorph" ofType:@"py"];
NSTask *task = [NSTask new];
[task setExecutableURL:[NSURL fileURLWithPath:@"/usr/bin/python"]];
[task setArguments:@[pythonScriptPath,@"-p1",image1Path,@"-p2",image2Path,@"-a",@"0.5",@"-ex",@"/Users/fofo/a3.jpg",@"-predictorpath",predictorPath]];
[task launch];
[task waitUntilExit];
如果我禁用沙盒,脚本运行得很好。但是,如果我启用沙盒,则输出如下:
Traceback (most recent call last):
File "/Users/fofo/Library/Developer/Xcode/DerivedData/FaceMorph_macOS-cmfgvhivheuzioacarvvcyjpokyp/Build/Products/Debug/FaceMorph macOS.app/Contents/Resources/faceMorph.py", line 4, in <module>
import cv2
ImportError: No module named cv2
非常感谢任何建议。谢谢。
解决方案
推荐阅读
- docker - Windows Docker 容器未显示在本地主机上接收“页面不工作”
- docker - Go - 使用 CompileDaemon 的 Docker 自动重载
- gcc - arm-none-eabi-gcc 不从代码中推断浮点乘法累加
- ionic-framework - 如何在 Ionic 4 中更改离子按钮的字体粗细?
- python - Pyinstaller:当我使用 pyinstaller 创建 .exe 文件时,在 python 中使用内置函数打开的可执行文件在 1 秒后关闭
- wpf - 数据绑定不适用于集合内的自定义控件
- kubernetes - Helm - 在 values.yaml 中模板化变量
- php - php password_hash() 未使用的字符
- reactjs - Redux + React Native + Expo - 在开发环境中,组件更新状态后不渲染,但在生产环境中可以使用
- excel - 刷新 OLEDB 连接时出错 - “对象 WorkbookConnection 的方法刷新失败”