aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-01-31 15:36:51 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-02-06 12:50:26 +0100
commitd9cfec8e010b48036e5e879ccc99879538a4f7d2 (patch)
treeef7afad8bf7d2c356997a444307da9d95dfe9f9c
parent683598e0b008078cb6cc00f2b22a75b6404ccc96 (diff)
Fix build on Windows using Python 3.8
The DLL load behavior was changed in Python 3.8 to no longer search the PATH variable for DLL dependencies. This means that the shiboken2.dll from the shiboken2 package is no longer found. Add the shiboken2 package using os.add_dll_directory() to fix this. Unfortunately, this requires additional work during the build process, Qt and libpyside2.dll need to be found in the build directory. Change-Id: I3d78d8df2d6f64913e06fa44e7e1aadbc1a14b58 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/pyside2/PySide2/__init__.py.in47
1 files changed, 37 insertions, 10 deletions
diff --git a/sources/pyside2/PySide2/__init__.py.in b/sources/pyside2/PySide2/__init__.py.in
index b6d0b89b3..8013ac68a 100644
--- a/sources/pyside2/PySide2/__init__.py.in
+++ b/sources/pyside2/PySide2/__init__.py.in
@@ -1,5 +1,6 @@
from __future__ import print_function
-
+import os
+import sys
__all__ = list("Qt" + body for body in
"@all_module_shortnames@"
@@ -7,20 +8,48 @@ __all__ = list("Qt" + body for body in
__version__ = "@FINAL_PACKAGE_VERSION@"
__version_info__ = (@BINDING_API_MAJOR_VERSION@, @BINDING_API_MINOR_VERSION@, @BINDING_API_MICRO_VERSION@, "@BINDING_API_PRE_RELEASE_VERSION_TYPE@", "@BINDING_API_PRE_RELEASE_VERSION@")
-def _setupQtDirectories():
- import sys
- import os
+def _additional_dll_directories(package_dir):
+ # Find shiboken2 relative to the package directory.
+ root = os.path.dirname(package_dir)
+ shiboken2 = os.path.join(root, 'shiboken2')
+ if os.path.isdir(shiboken2): # Standard case, only shiboken2 is needed
+ return [shiboken2]
+ # The below code is for the build process when generate_pyi.py
+ # is executed in the build directory. We need libpyside and Qt in addition.
+ shiboken2 = os.path.join(os.path.dirname(root), 'shiboken2', 'libshiboken')
+ if not os.path.isdir(shiboken2):
+ raise ImportError(shiboken2 + ' does not exist')
+ result = [shiboken2, os.path.join(root, 'libpyside')]
+ for path in os.environ.get('PATH').split(';'):
+ if path:
+ if os.path.exists(os.path.join(path, 'qmake.exe')):
+ result.append(path)
+ break
+ return result
+
+
+def _setupQtDirectories():
# On Windows we need to explicitly import the shiboken2 module so
# that the libshiboken.dll dependency is loaded by the time a
# Qt module is imported. Otherwise due to PATH not containing
# the shiboken2 module path, the Qt module import would fail
# due to the missing libshiboken dll.
+ # In addition, as of Python 3.8, the shiboken package directory
+ # must be added to the DLL search paths so that shiboken2.dll
+ # is found.
# We need to do the same on Linux and macOS, because we do not
# embed rpaths into the PySide2 libraries that would point to
# the libshiboken library location. Importing the module
# loads the libraries into the process memory beforehand, and
# thus takes care of it for us.
+
+ pyside_package_dir = os.path.abspath(os.path.dirname(__file__))
+
+ if sys.platform == 'win32' and sys.version_info[0] == 3 and sys.version_info[1] >= 8:
+ for dir in _additional_dll_directories(pyside_package_dir):
+ os.add_dll_directory(dir)
+
try:
import shiboken2
except Exception:
@@ -32,18 +61,16 @@ def _setupQtDirectories():
# Trigger signature initialization.
type.__signature__
- pyside_package_dir = os.path.abspath(os.path.dirname(__file__))
-
if sys.platform == 'win32':
# PATH has to contain the package directory, otherwise plugins
# won't be able to find their required Qt libraries (e.g. the
# svg image plugin won't find Qt5Svg.dll).
os.environ['PATH'] = pyside_package_dir + os.pathsep + os.environ['PATH']
- # On Windows add the PySide2\openssl folder (if it exists) to
- # the PATH so that the SSL DLLs can be found when Qt tries to
- # dynamically load them. Tell Qt to load them and then reset
- # the PATH.
+ # On Windows, add the PySide2\openssl folder (created by setup.py's
+ # --openssl option) to the PATH so that the SSL DLLs can be found
+ # when Qt tries to dynamically load them. Tell Qt to load them and
+ # then reset the PATH.
openssl_dir = os.path.join(pyside_package_dir, 'openssl')
if os.path.exists(openssl_dir):
path = os.environ['PATH']