目录:
- 官方文档翻译
- 编译MinGW版本
- 编译VS版本
下载SIP
SIP必现在编译和使用PyQt5之前安装。你可以从https://www.riverbankcomputing.com/software/sip/download使用最新的发布版本的源码。
SIP的安装说明请参阅http://pyqt.sourceforge.net/Docs/sip4/installation.html
当编译v5.11或以上的版本时,你必须配饰SIP来创建私有的备份。可以使用下面的命令:
python configure.py –sip-module PyQt5.sip –no-tools
下载PyQt5
你可以从https://www.riverbankcomputing.com/software/pyqt/download5下载最新的源码
如果你使用商业版的PyQt5,则需要购买商业授权,并下载属于你的pyqt-commercial.sip授权文件
配置PyQt5
解压后,你应该阅读相应平台的README文件。
如果你使用商业版的PyQt5,你必须复制你的pyqt-commercial.sip授权文件到sip文件夹,或者使用–license-dir参数指定。
你需要确定你的环境变量是否正确。
为了配置构建PyQt5,你需要运行以下脚本:
1 | python3 configure.py |
脚本完整的参数属性如下:
-h, --help
展示帮助信息
--allow-sip-warnings
5.9.1版本的新特性。
Normally any warning message generated by sip is treated as an error. This option causes warning messages to be considered non-fatal. It is normally only required if a later version of sip is being used that has deprecated a feature used by this version of PyQt5.
--assume-shared
Normally Qt is checked to see if it has been built as shared libraries. Some Linux distributions configure their Qt builds to make this check unreliable. This option ignores the result of the check and assumes that Qt has been built as shared libraries.
--bindir
pyuic5, pyrcc5 and pylupdate5工具将会安装到的目录。
--concatenate
The C++ source files for a Python module will be concatenated. This results in significantly reduced compilation times. Most, but not all, C++ compilers can handle the large files that result. See also the –concatenate-split option.
--concatenate-split
If the –concatenate option is used to concatenate the C++ source files then this option determines how many files are created. The default is 1.
--configuration
指定配置文件
--confirm-license
使用授权证书
Using this confirms that you accept the terms of the PyQt5 license. If it is omitted then you will be asked for confirmation during configuration.
--dbus
根据/dbus目录找到dbus-python.h头文件
The dbus-python.h header file of the dbus-python package can be found in the directory/dbus.
--debug
The PyQt5 modules will be built with debugging symbols. On Windows configure.py must be run using a debug version of Python.
--designer-plugindir
指定Qt Designer安装目录
--destdir
指定PyQt5安装目录。默认安装在Python的site-packages目录。如果你使用这个属性,则PYTHONPATH必须指定在
The PyQt5 Python package will be installed in the directory. The default is the Python installation’s site-packages directory. If you use this option then the PYTHONPATH environment variable must include.
--disable
5.5.1新特性
Normally all PyQt5 modules are enabled and are built if the corresponding Qt library can be found. This option will suppress the check for
--disable-feature
5.10.1新特性
A PyQt5 module may be configured differently depending on the corresponding Qt configuration. This takes the form of a set of features that may be disabled. Normally this is determined automatically. This option will explicitly disable the
--enable
Normally all PyQt5 modules are enabled and are built if the corresponding Qt library can be found. Using this option only those modules specifically enabled will be built. The option may be specified any number of times. Note that using this option suppresses the checks that are normally made to determine how the module should be configured, i.e. which features should be disabled.
--license-dir
指定授权证书的目录
The license files needed by the commercial version of PyQt5 can be found in the directory.
--link-full-dll
5.8版本新特性
On Windows the full Python API and the limited API (as used by PyQt) are implemented in different DLLs. Normally the limited DLL is linked (unless a debug version of the Python interpreter is being used to run configure.py). This option forces the full API DLL to be linked instead.
--no-designer-plugin
Qt Designer 插件将不会被编译
--no-dist-info
5.11新特性
This disables the creation of the PEP 376 .dist-info directory. Starting with this version a .dist-info directory is created. This contains meta-data about the installation including version information for dependent packages. It also means that pip can be used to uninstall the package.
--no-docstrings
PyQt5模块不会包含自动产生的文档字符串
The PyQt5 modules will not contain automatically generated docstrings.
--no-python-dbus
The Qt support for the standard Python DBus bindings is disabled.
--no-qml-plugin
qmlscene 插件不会被编译
--no-qsci-api
The PyQt5.api QScintilla API file is not installed even if QScintilla does appear to be installed.
--no-sip-files
The .sip files for the PyQt5 modules will not be installed.
--no-stubs
New in version 5.6.
The PEP 484 type hint stub files for the PyQt5 modules will not be installed. This option is ignored (and the stub files are not installed) for versions of Python earlier than v3.5.
--no-tools
New in version 5.3.
The pyuic5, pyrcc5 and pylupdate5 tools will not be built.
--no-timestamp
Normally the header comments of each generated C/C++ source file includes a timestamp corresponding to when the file was generated. This option suppresses the inclusion of the timestamp.
--protected-is-public
On certain platforms the size of PyQt5 modules can be significantly reduced by redefining the C++ protected keyword as public during compilation. This option enables this behaviour and is the default on Linux and macOS.
--protected-not-public
The default redefinition of protected to public during compilation on Linux and macOS is disabled.
--pyuic5-interpreter
--qmake
Qt’s qmake program is used to determine how your Qt installation is laid out. Normally qmake is found on your PATH. This option can be used to specify a particular instance of qmake to use.
--qml-debug
New in version 5.8.
Enable the QML debugging infrastructure. This should not be enabled in a production environment.
--qml-plugindir
The Python plugin for qmlscene will be installed in the directory.
--qsci-api
The PyQt5.api QScintilla API file is installed even if QScintilla does not appear to be installed. This option is implied if the –qsci-api-destdir option is specified.
--qsci-api-destdir
The QScintilla API file will be installed in the python subdirectory of the api subdirectory of the directory.
--qtconf-prefix
New in version 5.6.
A qt.conf file is embedded in the PyQt5.QtCore module with Prefix set to which is assumed to be relative to the directory that the PyQt5.QtCore module will be installed in.
--sip
The sip program is used to generate PyQt5’s C++ source code. Normally sip is found on your PATH. This option can be used to specify a particular instance of sip to use.
--sip-incdir
The sip.h header file can be found in the directory.
--sipdir
The .sip files for the PyQt5 modules will be installed in the directory.
--spec
The argument -spec SPEC will be passed to qmake. The default behaviour is platform specific. On Windows configure.py will choose the value that is correct for the version of Python that is being used. (However if you have built Python yourself then you may need to explicitly specify
--static
The PyQt5 modules will be built as static libraries. This is useful when building a custom interpreter with the PyQt5 modules built in to the interpreter.
--stubsdir
New in version 5.6.
The PEP 484 type hint stub files for the PyQt5 modules will be installed in the directory. By default they will be stored in the same directory where (by default) the corresponding extension modules would be installed. This option is ignored (and the stub files are not installed) for versions of Python earlier than v3.5.
--sysroot
New in version 5.3.
is the name of an optional directory that replaces sys.prefix in the names of other directories (specifically those specifying where the various PyQt5 components will be installed and where the Python include and library directories can be found). It is typically used when cross-compiling or when building a static version of PyQt5. See Configuring with Configuration Files.
--target-py-version
New in version 5.3.
--trace
The generated PyQt5 modules contain additional tracing code that is enabled using SIP’s sip.settracemask() function.
--verbose
Compiler commands and any output issued during configuration is displayed instead of being suppressed. Use this if configure.py is having problems to see what exactly is going wrong.
--version
显示版本号
编译PyQt5
make
make install
配置配置文件
配置文件的格式如下:
- 使用[]来表示一部分的名字
- 配置的条目为单一的行,用=分开的键值对
- 在值中可以使用%(name)的方式来嵌套其他的值
- 注释需要以#开头
- 空白行被忽略
配置文件通过定义不同的[]部分来使用不同的版本。configure.py将会选择对应的Qt版本。比如,如果配置文件包含Qt v5.1和Qt v5.3,你使用Qt v5.2.1,则会选择Qt v5.1的版本。
configure.py提供了以下预制变量:
py_major
对应Python安装最大的版本
py_minor
对应Python安装最小的版本
sysroot
系统根目录,可以使用–sysroot选项指定
下面是一个配置文件的实例:
# The target Python installation.
py_platform = linux
py_inc_dir = %(sysroot)/usr/include/python%(py_major).%(py_minor)
py_pylib_dir = %(sysroot)/usr/lib/python%(py_major).%(py_minor)/config
py_pylib_lib = python%(py_major).%(py_minor)mu
# The target PyQt installation.
pyqt_module_dir = %(sysroot)/usr/lib/python%(py_major)/dist-packages
pyqt_bin_dir = %(sysroot)/usr/bin
pyqt_sip_dir = %(sysroot)/usr/share/sip/PyQt5
pyuic_interpreter = /usr/bin/python%(py_major).%(py_minor)
pyqt_disabled_features = PyQt_Desktop_OpenGL PyQt_qreal_double
# Qt configuration common to all versions.
qt_shared = True
[Qt 5.1]
pyqt_modules = QtCore QtDBus QtDesigner QtGui QtHelp QtMultimedia
QtMultimediaWidgets QtNetwork QtOpenGL QtPrintSupport QtQml QtQuick
QtSensors QtSerialPort QtSql QtSvg QtTest QtWebKit QtWebKitWidgets
QtWidgets QtXmlPatterns _QOpenGLFunctions_ES2
下面的值可以在配置文件中指定:
qt_shared
设置Qt是否是动态共享文件,默认值为False
py_platform
Python目标平台
py_debug
is set if a debug version of the target Python is being used.
py_inc_dir
is the target Python include directory, i.e. the directory containing the Python.h file.
py_pylib_dir
is the target Python library directory.
py_pylib_lib
is the target Python interpreter library. It should not include any platform-specific prefix or suffix.
pyqt_disabled_features
is the space separated list of features (as defined by SIP’s %Feature directive) that should be disabled.
pyqt_module_dir
is the target directory where the PyQt5 modules will be installed. It can be overridden by the –destdir option.
pyqt_modules
is the space separated list of PyQt5 modules that will be built. It can be overridden by the –enable option.
pyqt_bin_dir
is the name of the target directory where the PyQt5 related executables will be installed. It can be overridden by the –bindir option.
pyqt_sip_dir
is the name of the target directory where the PyQt5 .sip files will be installed. It can be overridden by the –sipdir option.
pyuic_interpreter
is the name of the Python interpreter (as it would be called from the target system) that will be used to run pyuic5. It can be overridden by the –pyuic5-interpreter option.