Qt for Python/GettingStarted/Windows: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
Line 1: Line 1:
[[Category:Qt for Python]]   
[[Category:Qt for Python]]   
The Qt library has to be built with the same version of MSVC as Python and PySide2, this can be selected when using the online installer. 
                                                                                   
==== Requirements ====                                                             
* Qt package from https://www.qt.io or a custom build of Qt (preferably '''Qt 5.12''')
* A Python interpreter (version '''Python 3.5+'''). One possibility is to use a package from https://www.python.org/downloads/
** The official binary package of the Python 2.7 interpreter is not supported.  [[Qt_for_Python/Considerations#Missing_Windows_.2F_Python_2.7_release|Missing Windows / Python 2.7 release]]
* [https://www.microsoft.com/en-us/download/details.aspx?id=48159 MSVC2015] (for Python 3 on Windows)
* CMake from https://cmake.org/download/ ('''>= 3.1''')                             
* Git from https://git-scm.com/download/win ('''>= 2''')
* libclang (required for the 5.12 and dev branches) from [http://download.qt.io/development_releases/prebuilt/libclang/ download.qt.io] ('''6.0 or greater''')
* [https://sourceforge.net/projects/openssl/ OpenSSL] (optional for SSL support, Qt must have been configured using the same SSL library)
* virtualenv (strongly recommended, but optional)                                               
* Python sphinx package for documentation (optional, pip install sphinx)


=== Building from sources on Windows 10 ===
== Official documentation ==
The following steps are performed on the command prompt (''cmd'') that is included with the MSVC2015 package, to include the proper compiler configuration.
A 64bit infrastructure is assumed in the procedure, but if the host is a 32bit environment it is possible to just download the proper architecture packages.
The packages used on this process are:
* 7zip (''7z1700-x64'')
* Git (''Git-2.15.1.2-64'')
* CMake (''cmake-3.10.2-win64-x64'')
* Python (''python-3.6.4-amd64'')
* MSVC2015 or MSVC2017 (''visualcppbuildtools_full'')
* CLANG (''libclang-release_60-windows-vs2015_64.7z'')
* Qt 5.12 (''qt-unified-windows-x86-3.0.2-online'')


==== [Optional but recommended]: Creating a virtual environment using virtualenv ====
Refer to the [https://doc.qt.io/qtforpython/gettingstarted-windows.html official documentation] to get started on Windows.
 
''virtualenv'' allows you to create a local, user-writeable copy of a python environment into which arbitrary modules can be installed and which can be removed after use.
 
* virtual testenv
* call testenv\scripts\activate
 
will create and use a new virtual environment, which is indicated by the command prompt changing.
 
==== Setting up CLANG ====
* Download [http://download.qt.io/development_releases/prebuilt/libclang/ libclang], e.g.
[http://download.qt.io/development_releases/prebuilt/libclang/libclang-release_60-windows-vs2015_64-clazy.7z libclang-release_60-windows-vs2015_64-clazy.7z]
* Extract the files, e.g. using [http://www.7-zip.org/ 7zip]                       
* Move the directory ''libclang'' to any desired path, e.g ''c:\'', and then set these two required environment variables:
set LLVM_INSTALL_DIR=c:\libclang
set PATH=C:\libclang\bin;%PATH%
 
==== Getting PySide2 ====                                                 
* You must [https://git-scm.com/download/win download git] in order to clone the repository.
* Cloning the official repository
git clone --recursive https://code.qt.io/pyside/pyside-setup
* Checking out the version that we want to build, e.g. 5.12 (Keep in mind you need to use the same version as your Qt installation)
cd pyside-setup && git checkout 5.12
 
==== Building PySide2 ====                                               
* You must [https://www.python.org/downloads/windows/ download Python] to build PySide2 (3.6 is recommended)
* Check your Qt installation path, to specifically use that version of ''qmake'' to build PySide2.
e.g. ''E:\Qt\5.12.0\msvc2015_64\bin\qmake.exe''
* Build can take a few minutes, so it is recommended to use more than one CPU core (e.g. 8). Remember to replace the paths to your current ''qmake'' path:
python setup.py build --qmake=E:\Qt\5.12.0\msvc2015_64\bin\qmake.exe --openssl=C:\Dev\qtdev\OpenSSL-Win64\bin  --build-tests --ignore-git --jobs=8                                                                             
==== Installing PySide2 ====                                     
* To install on the current directory, just run:
python setup.py install --qmake=E:\Qt\5.12.0\msvc2015_64\bin\qmake.exe  --openssl=C:\Dev\qtdev\OpenSSL-Win64\bin --build-tests --ignore-git --parallel=8                                                                               
==== Test installation ====                                                     
* You can execute one of the examples to verify the process is properly working.
* Remember to properly set the environment variables for Qt and PySide2.
python examples/widgets/widgets/tetrix.py


== Build considerations ==
== Build considerations ==

Latest revision as of 10:54, 2 January 2020


Official documentation

Refer to the official documentation to get started on Windows.

Build considerations

Building PySide2 on Windows is a bit special in the sense that some rules have to be followed:

  • The MSVC version used to build Python, Qt and PySide2 must be the same. The only exception are MSVC2015 & MSVC2017 as those compilers produce compatible binaries.
    • In practice this means that if you use the official Python 3.x package from [1] which is built with MSVC 2015, you need to use a Qt package built with MSVC 2015 (or MSVC2017 due to the aforementioned compatibility).
    • Using the official Python 2.x package will not be feasible, due to it being built with MSVC 2008, and there being no official prebuilt Qt package for the same MSVC version.
  • The build configuration (debug or release) has to be the same for Python, Qt and PySide2.
  • The above considerations are necessary to ensure that only a single MSVC runtime library is loaded, otherwise this can cause memory corruption, crashes or undefined behavior.

Development

Development happens in the 5.12 and dev branches of the pyside-setup repository. The top level repository has the following submodules:

  • sources/pyside2-tools: uic, rcc tools
  • sources/pyside2-examples (5.6 only, examples are no longer a submodule in 5.9+)

Contributions follow the standard process. It is helpful to have debug binaries and/or symbols for Python available. On Windows, this is done by choosing Customized Installation when installing Python and ticking the respective check boxes. It is also recommended to use a Virtual Environment for testing to be able to always start from a clean base and avoid issues with write permissions in installations. On Windows an installation step may be required:

python -m pip install virtualenv                                                       
python -m virtualenv testenv                                                                                                                                           

The Virtual Environment is activated by·

CALL testenv\Scripts\activate.bat                                                                                                                                                                                                                                                                                              

Before building the first time, the module Sphinx should be installed into the virtual environment:·

pip install sphinx

Other useful modules are

pip install numpy PyOpenGL