Skip to content

Instantly share code, notes, and snippets.

@fyears
Created November 2, 2014 06:31
Show Gist options
  • Save fyears/673b2d763720f3c26256 to your computer and use it in GitHub Desktop.
Save fyears/673b2d763720f3c26256 to your computer and use it in GitHub Desktop.
pyside+qml+pyinstaller
pyinstaller -F -w --noupx main.spec
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtDeclarative import QDeclarativeView
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller
http://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile
"""
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
# Create Qt application and the QDeclarative view
app = QApplication(sys.argv)
view = QDeclarativeView()
# Create an URL to the QML file
url = QUrl(resource_path('./view.qml'))
# Set the QML file and show
view.setSource(url)
view.show()
# Enter Qt main loop
sys.exit(app.exec_())
# -*- mode: python -*-
block_cipher = None
a = Analysis(['main.py'],
pathex=['.'],
hiddenimports=[],
hookspath=None,
runtime_hooks=None,
cipher=block_cipher)
a.datas += [('view.qml', 'view.qml', 'DATA')]
pyz = PYZ(a.pure,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='main.exe',
debug=False,
strip=None,
upx=False,
console=False )
import QtQuick 1.0
Rectangle {
width: 200
height: 200
color: "red"
Text {
text: "Hello World"
anchors.centerIn: parent
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment