[英]iOS 6: libpython2.7.a initialization import error
堅持在iOS上初始化嵌入式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 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文件放在基本程序文件中作為目錄(不是組) - 在構建階段添加此目錄“上載資源”列表 - 在構建階段將“上傳資源”階段放在“編譯程序”之上”。 不知道為什么,但它有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.