2016-11-18 30 views
1

我想用pyinstaller打包一個PyQt應用程序。我simplyfied目錄樹看起來如下:pyinstaller:從導入的模塊添加缺少的數據

maindir/ 
├── build/ 
├── dev_tool.py 
├── dev_tool.spec 
├── dist 
│   └── dev_tool/ 
└── ... 

當我從dist/文件夾

$ ./dist/dev_tool/dev_tool

運行可執行文件dev_tool我得到的錯誤,這是無法找到.../dev_tool/langdetect/utils/messages.properties。但是,當我手動添加langdetect文件夾(我簡單地從我的python站點包中複製pip install langdetect -ed後)它可以工作。現在我通過在.spec文件here中定義它來了解如何添加文件,但是,如果我嘗試將langdetect/文件夾從我的Python站點包複製到dist/dev_tool/文件夾中,它仍然不起作用。

添加以下行到我的dev_tool.spec文件

a = Analysis (... 
datas=[('path_to.../site-packages/langdetect', 'dist/dev_tool/langdetect')] 
...) 

不應該在該副本一切從站點包langdetect文件夾dist/dev_tool/langdetect/

這裏的任何幫助將非常感激。

回答

0

您可以使用PyInstallerTree類。

# dev_tool.spec 
langdetect_toc = Tree('C:\\[site-packages]\\langdetect', 
         prefix='langdetect', 
         excludes=['*.py','*.pyc', '*test*']) 
a.datas += langdetect_toc 

然後用dev_tool.spec作爲參數將從langdetect所有必要的數據文件放到dist\dev_tool\langdetect所以dev_tool在運行時可以找到它們運行pyinstaller

0

這爲我工作:

a = Analysis(
    # your other stuff here... 
    datas=[ 
     ('langdetect/utils', 'csg_fileutil_libs/langdetect/utils'), # for messages.properties file 
     ('langdetect/profiles', 'csg_fileutil_libs/langdetect/profiles'), 
      ] 
    # the rest of your analysis spec... 
    )