2016-07-08 154 views
0

我想用pyinstaller打包我的程序。代碼在Windows上運行良好,並使用SqlAlchemy,OpenCV和pyodbc包。Python:Sqlalchemy搞砸pyinstaller?

我運行pyinstaller來創建可執行文件並試圖運行它。我發現了一個錯誤:

ImportError: No module named ConfigParser 
現在

,我重新進行了同樣的事情,看着從pyinstaller日誌,並得到了一個警告:

WARNING: Hidden import "sqlalchemy.sql.functions.func" not found! 

與其他幾個人一起。 然後出現了關於試圖以大寫和小寫導入ConfigParser的警告。

Attempted to add Python module twice with different upper/lowercases: ConfigParser 

這裏有什麼問題?

回答

0

所以,我想通了。在一定程度上。
看起來像pyInstaller沒有處理好SWIG文件。

sqlalchemy.utils有一個名爲compat.py的文件。它可以使模塊與所有版本的python兼容。

例如,在python2.x,有ConfigParser而在PY3,它被命名爲configparser
所以在compat.py的一部分來對付它:

if py3: 
    import configparser 
    # Some other such import statements 
elif py2: 
    import ConfigParser as configparser 

現在,pyinstaller被難倒因爲它只是側重於進口,因此它試圖進口並且慘敗。
我對此的粗略解決方法涉及修改compat.py文件並僅保留與Python版本相關的部分(2.x)。
再次運行pyinstaller證明是成功的! :)

雖然這一切都很粗糙,可能有更好的東西,但我找不到任何東西,所以我分享了對我有用的東西。