近來在做一個C++嵌入python的程序,剛開始一直在本機跑,一切正常,后來拿到別人機子上就無法運行了。本以為是缺少了python27.dll,結果發現不止缺少這一個文件,貌似還缺少很多python的庫文件。
于是通過關鍵字“C++嵌入python 發布”,找到了一個用py2exe來解決問題,但我試了半天都沒成功(也許是我自己沒弄對的原因,因為人家都成功了)。
再后來我把關鍵字改為了“python C++ distribute embed”(即英文關鍵字),這下撥云見天了,因為在Google的第一頁就有一個外國帖子其標題正和我意(果然英語給力)。
看了那個貼子發現,之所以不能在沒有安裝python的機子上運行是因為:
“
In addition to pythonxy.dll, you also need the entire Python library, i.e. the contents of the lib folder, plus the extension modules, i.e. the contents of the DLLs folder. Without the standard library, Python won't even start, since it tries to find os.py (in 3.x; string.py in 2.x). On startup, it imports a number of modules, in particular site.py.
”
原文:
http://stackoverflow.com/questions/1387906/c-with-python-embedding-crash-if-python-not-installed
posted on 2011-04-25 09:57
zhaoyg 閱讀(1282)
評論(0) 編輯 收藏 引用 所屬分類:
C++和Python