当前位置:首页 > 操作系统 > Ios

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

坚持初始化iOS上的Embedded Python.
我从Kivy项目中获取了构建脚本.
它产生了libpython2.7.a,Python27.zip并包含.

因此,我的应用将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 snprint(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文件放置在基本程序文件中作为目录(而不是组)
-在构建阶段“上传资源”列表中添加此目录
-在构建阶段,将“上传资源”阶段置于“编译程序”之上.不知道为什么,但是有帮助.


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!