此页面聚焦于从源代码构建 Qt for Python,若仅仅希望安装 PySide2 采用
pip
,需要运行:
pip install pyside2
更多细节,参考 快速入门 指南。此外,可以检查 FAQ 相关工程。
Python :3.5+ 和 2.7
Qt: 推荐 5.12+
libclang: libclang 库,推荐:PySide2 5.12 第 6 版。预建版本可以从 这里下载 .
CMake: 需要 3.1+。
可以参考以下特定平台指导页面:
移动平台 (iOS/Android) (不支持)
嵌入式平台 (没有官方支持)
注意
大多数基于 Linux 的嵌入式 OS 为 PySide2 提供官方包管理器 (如 Raspbian and ArchlinuxARM ).
正常构建命令看起来像这样:
python setup.py install --qmake=/path/to/qmake \
--ignore-git \
--debug \
--build-tests \
--parallel=8 \
--make-spec=ninja \
--verbose-build \
--module-subset=Core,Gui,Widgets
当构建和安装工程采用 debug 符号时,要包括 tests ,使用 ninja (而不是 make),并只考虑 模块子集 的 QtCore、QtGUI 及 QtWidgets。
--cmake
指定 CMake 二进制文件路径,
--reuse-build
仅重构修改文件,
--openssl=/path/to/openssl/bin
,使用不同 OpenSSL 路径,
--standalone
将 Qt 库复制到最终包中,使其能够在其它机器上工作,
--doc-build-online
使用在线模板构建文档编制。
使用
--build-tests
选项使我们能够在工程内运行所有自动测试:
python testrunner.py test > testlog.txt
注意
在 Windows,别忘记 qmake 路径 (
set
PATH=E:\Path\to\Qt\5.14\msvc2017_64\bin;%PATH%
)
还可以运行特定测试 (例如
qpainter_test
) 通过运行:
ctest -R qpainter_test --verbose
要生成文档编制使用 qdoc 以获取 API 信息,及 sphinx 对于本地 Python 相关注意事项。
系统需要
libxml2
and
libxslt
,及 Python 环境中,
sphinx
and
graphviz
需要在运行安装进程之前安装:
pip install graphviz sphinx
之后安装
graphviz
,
dot
命令需要位于 PATH 中,否则,进程将失败。安装
graphviz
system-wide is also an option.
Since the process rely on a Qt installation, you need to specify where the
qtbase
directory you will use with your
qmake
is located:
export QT_SRC_DIR=/path/to/qtbase
Once the build process finishes, you can go to the generated
*_build/*_release/pyside2
directory, and run:
make apidoc
注意
apidoc
make target builds offline documenation in QCH (Qt Creator Help) format by default. You can switch to building for the online use with the
--doc-build-online
configure option.
Finally, you will get a
html
directory containing all the generated documentation. The offline help files,
PySide.qch
and
Shiboken.qch
, can be moved to any directory of your choice. You can find
Shiboken.qch
in the build directory,
*_build\*_release\shiboken2\doc\html
.
The offline documentation (QCH) can be viewed using the Qt Creator IDE or Qt Assistant, which is a standalone application for viewing QCH files.
To view the QCH using Qt Creator, following the instructions outlined in 使用 Qt Creator 帮助模式 . If you chose to use Qt Assistant instead, use the following command to register the QCH file before launching Qt Assistant:
assistant -register PySide.qch
注意
Qt Assistant renders the QCH content using the QTextBrowser backend, which supports a subset of the CSS styles, However, Qt Creator offers an alternative litehtml-based backend, which offers better browsing experience. At the moment, this is not the default backend, so you have to select the litehtml backend explicitly under the
General
tab in
Qt
Creator
>>
工具
>>
Options
>>
Help
.
A set of tools can be found under the
tools/
directory inside the
pyside-setup
repository.
checklibs.py
: Script to analyze dynamic library dependencies of Mach-O binaries. To use this utility, just run:
python checklibs.py /path/to/some.app/Contents/MacOS/Some
This script was fetched from this repository .
create_changelog.py
: Script used to create the CHANGELOG that you can find in the
dist/
directory. Usage:
python create_changelog.py -r 5.14.1 -v v5.14.0..5.14 -t bug-fix
debug_windows.py
: This script can be used to find out why PySide2 modules fail to load with various DLL errors like Missing DLL or Missing symbol in DLL.
You can think of it as a Windows version of
ldd
/
LD_DEBUG
.
Underneath it uses the
cdb.exe
command line debugger, and the
gflags.exe
tool, both installed with the latest Windows Kit.
The aim is to ask users to run this script when they encounter PySide2 imports not working on Windows. The user should then provide the generated log file.
Incidentally it can also be used for any Windows executables, not just Python. To use it just run:
python debug_windows.py
missing_bindings.py
: This script is used to compare the state of PySide2 and PyQt5 regarding available modules and classses. This content is displayed in our
wiki page
, and can be used as follows:
python missing_bindings.py --qt-version 5.14.1 -w all
Please keep in mind we rely on BeautifulSoup to parse the content, so you will be to install it besides PySide2 and PyQt5 (Including additional modules like DataVisualiztion, QtCharts, WebEngine, etc).