gpt4 book ai didi

python - iOS 6 : libpython2. 7.a初始化导入错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:49:56 24 4
gpt4 key购买 nike

卡在初始化 iOS 上的嵌入式 Python 上。我从 Kivy 项目中获取了构建脚本。它生成了 libpython2.7.a、Python27.zip 和 include。

因此,我的应用将 zip 解压到/Documents/lib/python2.7

尝试设置 Python:

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
Py_SetPythonHome((char *)[docsDir UTF8String]);
Py_SetProgramName("");
Py_Initialize();

落在:

ImportError: No module named site

据我了解,它无法找到 Python 主路径。但是,如果我通过以下方式修复网站:

Py_NoSiteFlag=1;
PyRun_SimpleString("import sys as s\nprint(s.path)");

它输出有效路径:

['/var/mobile/Applications/1BC015FC-2F7A-41C0-8F3A-70A22510C3A3/Documents/lib/python27.zip', '/var/mobile/Applications/1BC015FC-2F7A-41C0-8F3A-70A22510C3A3/Documents/lib/python2.7/', '/var/mobile/Applications/1BC015FC-2F7A-41C0-8F3A-70A22510C3A3/Documents/lib/python2.7/plat-darwin', '/var/mobile/Applications/1BC015FC-2F7A-41C0-8F3A-70A22510C3A3/Documents/lib/python2.7/plat-mac', '/var/mobile/Applications/1BC015FC-2F7A-41C0-8F3A-70A22510C3A3/Documents/lib/python2.7/plat-mac/lib-scriptpackages', '/var/mobile/Applications/1BC015FC-2F7A-41C0-8F3A-70A22510C3A3/Documents/lib/python2.7/lib-tk', '/var/mobile/Applications/1BC015FC-2F7A-41C0-8F3A-70A22510C3A3/Documents/lib/python2.7/lib-old', '/var/mobile/Applications/1BC015FC-2F7A-41C0-8F3A-70A22510C3A3/Documents/lib/python2.7/lib-dynload']

但是没有一个导入有效。我必须解决什么问题才能使 Python 正确使用模块?

最佳答案

我已经自己修好了。我的错误是:- 需要将所有 python/lib 文件作为目录(而不是组)放在基本程序文件中- 在构建阶段“上传资源”列表中添加此目录- 在构建阶段将“上传资源”阶段置于“编译程序”之上。不知道为什么,但它有帮助。

关于python - iOS 6 : libpython2. 7.a初始化导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13343184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com