Skip to content

Commit

Permalink
Merge pull request pyinstaller#1136 from matysek/develop
Browse files Browse the repository at this point in the history
Fix pyinstaller#521: Extend Windows PATH  for PySide, PyQt4, PyQt5 hooks with Qt4 dlls.
  • Loading branch information
matysek committed Jan 3, 2015
2 parents e03f5f4 + b4b5d62 commit 6cf2d0f
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 5 deletions.
23 changes: 23 additions & 0 deletions PyInstaller/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import dircache # Module removed in Python 3
import os
import platform
import site
import subprocess
import sys

Expand Down Expand Up @@ -333,3 +334,25 @@ def __add_obsolete_options(parser):
**{'action': 'callback',
'callback': __obsolete_option,
'help': 'These options do not exist anymore.'})


# Site-packages functions - use native function if available.
if hasattr(site, 'getsitepackages'):
getsitepackages = site.getsitepackages
# Backported For Python 2.6 and virtualenv.
# Module 'site' in virtualenv might not have this attribute.
else:
def getsitepackages():
"""
Return only one item as list with one item.
"""
# For now used only on Windows. Raise Exception for other platforms.
if is_win:
pths = [os.path.join(sys.prefix, 'Lib', 'site-packages')]
# Include Real sys.prefix for virtualenv.
if is_virtualenv:
pths.append(os.path.join(venv_real_prefix, 'Lib', 'site-packages'))
return pths
else:
# TODO Implement for Python 2.6 on other platforms.
raise NotImplementedError()
12 changes: 11 additions & 1 deletion PyInstaller/hooks/hook-PyQt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@
#-----------------------------------------------------------------------------


import os

from PyInstaller.hooks.hookutils import qt4_menu_nib_dir
from PyInstaller.compat import is_darwin
from PyInstaller.compat import getsitepackages, is_darwin, is_win


# On Windows system PATH has to be extended to point to the PyQt4 directory.
# The PySide directory contains Qt dlls. We need to avoid including different
# version of Qt libraries when there is installed another application (e.g. QtCreator)
if is_win:
from PyInstaller.utils.winutils import extend_system_path
extend_system_path([os.path.join(x, 'PyQt4') for x in getsitepackages()])


# In the new consolidated mode any PyQt depends on _qt
Expand Down
12 changes: 11 additions & 1 deletion PyInstaller/hooks/hook-PyQt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@
#-----------------------------------------------------------------------------


import os

from PyInstaller.hooks.hookutils import qt5_menu_nib_dir
from PyInstaller.compat import is_darwin
from PyInstaller.compat import getsitepackages, is_darwin, is_win


# On Windows system PATH has to be extended to point to the PyQt4 directory.
# The PySide directory contains Qt dlls. We need to avoid including different
# version of Qt libraries when there is installed another application (e.g. QtCreator)
if is_win:
from PyInstaller.utils.winutils import extend_system_path
extend_system_path([os.path.join(x, 'PyQt4') for x in getsitepackages()])


# In the new consolidated mode any PyQt depends on _qt
Expand Down
12 changes: 11 additions & 1 deletion PyInstaller/hooks/hook-PySide.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
#-----------------------------------------------------------------------------


from PyInstaller.compat import is_darwin
import os

from PyInstaller.compat import getsitepackages, is_darwin, is_win
from PyInstaller.hooks.hookutils import qt4_menu_nib_dir


# On Windows system PATH has to be extended to point to the PySide directory.
# The PySide directory contains Qt dlls. We need to avoid including different
# version of Qt libraries when there is installed another application (e.g. QtCreator)
if is_win:
from PyInstaller.utils.winutils import extend_system_path
extend_system_path([os.path.join(x, 'PySide') for x in getsitepackages()])


# For Qt to work on Mac OS X it is necessary to include directory qt_menu.nib.
# This directory contains some resource files necessary to run PyQt or PySide
# app.
Expand Down
12 changes: 12 additions & 0 deletions PyInstaller/utils/winutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,15 @@ def get_system_path():
_bpath = [sys_dir, get_windows_dir()]
_bpath.extend(compat.getenv('PATH', '').split(os.pathsep))
return _bpath


def extend_system_path(paths):
"""
Add new paths at the beginning of environment variable PATH.
Some hooks might extend PATH where PyInstaller should look for dlls.
"""
old_PATH = compat.getenv('PATH', '')
paths.append(old_PATH)
new_PATH = os.pathsep.join(paths)
compat.setenv('PATH', new_PATH)
7 changes: 6 additions & 1 deletion bootloader/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ Bootloader building script.
import os
import platform
import sys
import sysconfig

# Workaround for Python 2.6. 'sysconfig' is not available in Python 2.6.
try:
import sysconfig
except ImportError:
import distutils.sysconfig as sysconfig

import Utils
import Options
Expand Down
2 changes: 1 addition & 1 deletion tests/interactive/test_pyqt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self):
u"Press <ESC> to exit. Some non-ascii chars: řčšěíáŘ",
self)
self.setWindowTitle("Hello World from PyQt4")
#self.resize(500, 300)
self.resize(400, 200)
self.show()

def sizeHint(self):
Expand Down
49 changes: 49 additions & 0 deletions tests/interactive/test_pyside.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
# Copyright (c) 2015, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------


import sys

from PySide import QtCore
from PySide import QtGui

class MyDialog(QtGui.QDialog):

def __init__(self):
super(MyDialog, self).__init__()

self.label = QtGui.QLabel(
u"Press <ESC> to exit. Some non-ascii chars: řčšěíáŘ",
self)
self.setWindowTitle("Hello World from PySide")
self.resize(400, 200)
self.show()

def sizeHint(self):
return self.label.sizeHint()

def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Escape:
self.close()


def main():
app = QtGui.QApplication(sys.argv)
read_formats = ', '.join([unicode(format).lower() \
for format in QtGui.QImageReader.supportedImageFormats()])
print("Qt4 plugin paths: " + unicode(list(app.libraryPaths())))
print("Qt4 image read support: " + read_formats)
print('Qt4 Libraries path: ' + unicode(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.LibrariesPath)))
ex = MyDialog()
app.exec_()


if __name__ == "__main__":
main()

0 comments on commit 6cf2d0f

Please sign in to comment.