我正在使用Python 2.7和PySide 1.1.2開展一個項目。我的代碼在我的GNU/Linux上沒有任何問題,但我想分發給Windows(7和8)。我不能指望用戶安裝Python和PySide,所以我決定使用py2exe(我也試過cx_freeze和pyinstaller)。如何在使用py2exe時包含ui和圖像文件?
首先,這裏是我的文件樹:My Project on GitHub
我創建了一個setup.py,那就是:
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
setup(
console=['bin/metusuite.py'],
name='metusuite',
version='0.1',
author='H. Gökhan Sarı',
author_email='[email protected]',
packages=['metusuite_libs'],
package_dir={'metusuite_libs': 'metusuite_libs'},
package_data={'metusuite_libs': ['ui/*', 'images/*']},
scripts=['bin/metusuite.py'],
url='https://github.com/th0th/metusuite/',
license='LICENSE.txt',
description='METU Suite.',
long_description=open('README.md').read(),
)
當我運行
setup.py py2exe
它成功建立但是,由於應用程序依賴於外部用戶界面文件 - 使用Qt Designer創建,並且無法找到它們,所以出現錯誤:
Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document.
Traceback (most recent call last):
File "metusuite.py", line 38, in <module>
File "metusuite_libs\msCafeteriaMenu.pyc", line 37, in __init__
File "metusuite_libs\msCafeteriaMenu.pyc", line 17, in __init__
RuntimeError: Unable to open/read ui device
而我無法弄清楚如何將* .ui文件(也有一些.png圖標)添加到該結構中。我正在考慮將.ui文件轉換爲Python代碼,然後當我需要添加一些圖標時遇到同樣的問題。
因此,如何添加我的ui和png文件在py2exe結構中?還是有什麼替代方法,我想要完成什麼?