admin管理员组文章数量:1123008
使用PySide2创建图形化Python程序时:Available platform plugins are: direct2d, minimal, offscreen, windows
修改E:\Anaconda3\Lib\site-packages\PySide2的__init__.py
加入第二段代码
from __future__ import print_function
import os
import sys
from textwrap import dedentdirname = os.path.dirname(__file__)
plugin_path = os.path.join(dirname,'plugins','platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']=plugin_path__all__ = list("Qt" + body for body in"Core;Gui;Widgets;PrintSupport;Sql;Network;Test;Concurrent;WinExtras;Xml;XmlPatterns;Help;Multimedia;MultimediaWidgets;OpenGL;OpenGLFunctions;Positioning;Location;Qml;Quick;QuickControls2;QuickWidgets;RemoteObjects;Scxml;Script;ScriptTools;Sensors;SerialPort;TextToSpeech;Charts;Svg;DataVisualization;UiTools;AxContainer;WebChannel;WebEngineCore;WebEngine;WebEngineWidgets;WebSockets;3DCore;3DRender;3DInput;3DLogic;3DAnimation;3DExtras".split(";"))
__version__ = "5.15.2"
__version_info__ = (5, 15, 2, "", "")def _additional_dll_directories(package_dir):# Find shiboken2 relative to the package directory.root = os.path.dirname(package_dir)# Check for a flat .zip as deployed by cx_free(PYSIDE-1257)if root.endswith('.zip'):return []shiboken2 = os.path.join(root, 'shiboken2')if os.path.isdir(shiboken2): # Standard case, only shiboken2 is neededreturn [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)breakreturn resultdef _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 shiboken2except Exception:paths = ', '.join(sys.path)print('PySide2/__init__.py: Unable to import shiboken2 from {}'.format(paths),file=sys.stderr)raise# Trigger signature initialization.try:# PYSIDE-829: Avoid non-existent attributes in compiled code (Nuitka).# We now use an explicit function instead of touching a signature._init_pyside_extension()except AttributeError:print(dedent('''\{stars}PySide2/__init__.py: The `signature` module was not initialized.This libshiboken module was loaded from"{shiboken2.__file__}".Please make sure that this is the real shiboken2 binary and not just a folder.{stars}''').format(stars=79*"*", **locals()), file=sys.stderr)raiseif 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 (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']try:os.environ['PATH'] = openssl_dir + os.pathsep + pathtry:from . import QtNetworkexcept ImportError:passelse:QtNetwork.QSslSocket.supportsSsl()finally:os.environ['PATH'] = path_setupQtDirectories()
本文标签:
版权声明:本文标题:使用PySide2创建图形化Python程序时:Available platform plugins are: direct2d, minimal, offscreen, windows 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1687654366a125336.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论