Qt for Python/GettingStarted/X11: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Adding Python debugging symbols option)
(27 intermediate revisions by 6 users not shown)
Line 1: Line 1:
(Page under development)
[[Category:Qt for Python]] 
 
==== Requirements ====                                               
==== Requirements ====                                               
* '''GCC''' (Linux)                                                                                                                                                                                                                           
* '''GCC''' (Linux)                                                                                                                                                                                                                           
* Python from https://www.python.org/downloads/ ('''Python 3.6''' or '''Python 2.7''')
* A Python interpreter (version '''Python 3.5+''' or '''Python 2.7'''). One possibility is to to use a package from https://www.python.org/downloads/ , a system installed package with an appropriate version should work as well.
* [http://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run Qt 5.6+]
* [http://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run Qt 5.12]
* [http://download.qt.io/development_releases/prebuilt/libclang/ CLANG 3.9] (for 5.9+ branches)
* [http://download.qt.io/development_releases/prebuilt/libclang/ libclang 6.0] (for 5.12)          
* [https://www.openssl.org/source/openssl-1.0.2n.tar.gz OpenSSL 1.0]               
* CMake from https://cmake.org/download/ ('''>= 3.1''')
* CMake from https://cmake.org/download/ ('''>= 3.1''')                            
* Git ('''>=2''')                                       
* [https://llvm.org/ LLVM]                                                         
* virtualenv ('''strongly recommended''', but optional)                                               
* virtualenv (optional but recommended)                                               
* Python sphinx package for documentation (optional, pip install sphinx)
* Python sphinx package for documentation (optional, pip install sphinx)            
* Depending on the distribution used, other dependencies may be required, such as: 
                                                                                   
** libgl-dev
** python-dev (or python3-dev)
** python-distutils (or python3-distutils)
** python-setuptools (or python3-setuptools)
 
=== Building from sources ===
=== Building from sources ===


Line 17: Line 20:


* Download [http://download.qt.io/development_releases/prebuilt/libclang/ libclang], e.g.
* Download [http://download.qt.io/development_releases/prebuilt/libclang/ libclang], e.g.
  wget http://download.qt.io/development_releases/prebuilt/libclang/libclang-release_39-linux-Rhel7.2-gcc5.3-x86_64.7z
  wget https://download.qt.io/development_releases/prebuilt/libclang/libclang-release_60-linux-Rhel7.2-gcc5.3-x86_64-clazy.7z


* Extract the files, e.g.
* Extract the files, e.g.
  7z x libclang-release_39-linux-Rhel7.2-gcc5.3-x86_64.7z                            
  7z x libclang-release_60-linux-Rhel7.2-gcc5.3-x86_64-clazy.7z                          


* Export the installation path to the path you choosed to place the files
* Export the installation path to the path you choosed to place the files
Line 27: Line 30:
==== Getting PySide2 ====                                                   
==== Getting PySide2 ====                                                   


* Clonning the official repository
* Clone the official repository:
  git clone --recursive https://codereview.qt-project.org/pyside/pyside-setup        
  git clone --recursive https://code.qt.io/pyside/pyside-setup
 
* Check out the version you want to build, e.g. 5.12. Keep in mind that you must use the same version as your Qt installation.
* Checking out the version that we want to build, e.g. 5.9 (Keep in mind you need to use the same version as your Qt installation)
  cd pyside-setup && git checkout 5.12
  cd pyside-setup && git checkout 5.9                                                               


==== Building PySide2 ====                                                 
==== Building PySide2 ====                                                 
Line 38: Line 40:
  which qmake
  which qmake


* Check your OpenSSL installation path, to specify it to build PySide2:
* 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:
  which openssl
  python setup.py build --qmake=/path/to/qmake --build-tests --ignore-git --parallel=8


* 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'' and ''openssl'' path:
python setup.py build --qmake=/path/to/qmake  --openssl=/path/to/openssl --build-tests --ignore-git --jobs=8
                                                                                   
==== Installing PySide2 ====                                       
==== Installing PySide2 ====                                       


* To install on the current directory, just run:
* To install on the current directory, just run:
  python setup.py install --qmake=/path/to/qmake  --openssl=/path/to/openssl --build-tests --ignore-git --jobs=8
  python setup.py install --qmake=/path/to/qmake  --openssl=/path/to/openssl --build-tests --ignore-git --parallel=8
                                                                                   
 
==== Test installation ====                                                       
==== Test installation ====                                                       
* You can execute one of the examples to verify the process is properly working.
* 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.
* Remember to properly set the environment variables for Qt and PySide2.
  python examples/examples/widgets/widgets/tetrix.py
  python examples/widgets/widgets/tetrix.py
               
 
== Development ==                                                                     
== Development ==                                                                     
                                                                                      
                                                                                      
Development happens in the 5.9 and dev branches of the [http://code.qt.io/cgit/pyside/pyside-setup.git/ pyside-setup repository].
Development happens in the 5.12 and dev branches of the [http://code.qt.io/cgit/pyside/pyside-setup.git/ pyside-setup repository].
                                                                                      
                                                                                      
The top level repository has the following submodules:                               
The top level repository has the following submodules:                               
* sources/pyside2-tools: uic, rcc tools
* sources/pyside2-tools: uic, rcc tools
* examples/                                            
* examples/ (5.6 only, examples are no longer a submodule in 5.9+)
                                                                                      
                                                                                      
Contributions follow the [[Qt_Project_Guidelines|standard process]].
Contributions follow the [[Qt_Project_Guidelines|standard process]].
Line 68: Line 67:
(e.g.: Ubuntu, the packages python3-dbg, libpython3-dbg provide a debug binary python3-dbg)
(e.g.: Ubuntu, the packages python3-dbg, libpython3-dbg provide a debug binary python3-dbg)


If your distribution does not include them, you can download python
If your distribution does not include them, you can [https://www.python.org/downloads/ download python] sources
and compile it by yourself, e.g.
and compile it by yourself, e.g.
  ./configure --prefix=/your/installation/path CFLAGS="-O0 -fno-inline -fno-omit-frame-pointer -g" LDFLAGS="-O0" CPPFLAGS="-O0" OPT="-O0 -g"
  ./configure --prefix=/where/to/install/python/path CFLAGS="-O0 -fno-inline -fno-omit-frame-pointer -g" LDFLAGS="-O0" CPPFLAGS="-O0" OPT="-O0 -g"
  make
  make
  make install
  make install
                                                                                   
 
It is also recommended to use a [http://docs.python-guide.org/en/latest/dev/virtualenvs/ Virtual Environment] for testing to be able to always start from a clean base and avoid issues with write permissions in installations.
It is also recommended to use a [http://docs.python-guide.org/en/latest/dev/virtualenvs/ Virtual Environment] for testing to be able to always start from a clean base and avoid issues with write permissions in installations.


Line 80: Line 79:
Please take into consideration that the binary name might be different in your system,
Please take into consideration that the binary name might be different in your system,
and that you can choose a different name for the environment instead of ''testenv''.
and that you can choose a different name for the environment instead of ''testenv''.
==== Troubleshooting ====
* '''Wrong RUNPATH / rpath'''
If you choose to build Python from sources in shared library configuration, it might be the case that the rpath is not set properly, which means that the built python binary might use the system python shared library, instead of the custom build shared library.
You can ''patch'' the interpreter rpath values with a binary that PySide2 provides:
cd pyside-setup
./patchelf --set-rpath /path/to/your/local/python/lib /path/to/your/python/virtualenv/binary/python
And then you can proceed to re-install PySide2.
(you can check if the patch worked with ''readelf -d /path/to/your/python/virtualenv/binary/python'')
* '''Missing libICU causes linking problems'''
From 5.9+ you can get a copy of libICU by specifying ''--standalone'' (but not including ''--iculib-url'') as an argument to ''setup.py'' execution.
* '''Recompile with -fPIC'''
This issue is usually encountered when using pyenv in a Linux distribution. It's necessary to reinstall python using pyenv with the following addendum: <syntaxhighlight>
env PYTHON_CFLAGS=-fPIC pyenv install -v 2.7.8
</syntaxhighlight>

Revision as of 08:29, 3 September 2019

Requirements

  • GCC (Linux)
  • A Python interpreter (version Python 3.5+ or Python 2.7). One possibility is to to use a package from https://www.python.org/downloads/ , a system installed package with an appropriate version should work as well.
  • Qt 5.12
  • libclang 6.0 (for 5.12)
  • CMake from https://cmake.org/download/ (>= 3.1)
  • Git (>=2)
  • virtualenv (strongly recommended, but optional)
  • Python sphinx package for documentation (optional, pip install sphinx)
  • Depending on the distribution used, other dependencies may be required, such as:
    • libgl-dev
    • python-dev (or python3-dev)
    • python-distutils (or python3-distutils)
    • python-setuptools (or python3-setuptools)

Building from sources

Setting up CLANG

wget https://download.qt.io/development_releases/prebuilt/libclang/libclang-release_60-linux-Rhel7.2-gcc5.3-x86_64-clazy.7z
  • Extract the files, e.g.
7z x libclang-release_60-linux-Rhel7.2-gcc5.3-x86_64-clazy.7z                            
  • Export the installation path to the path you choosed to place the files
export CLANG_INSTALL_DIR=$PWD/libclang                                               
                                                                                    

Getting PySide2

  • Clone the official repository:
git clone --recursive https://code.qt.io/pyside/pyside-setup
  • Check out the version you want to build, e.g. 5.12. Keep in mind that you must use the same version as your Qt installation.
cd pyside-setup && git checkout 5.12

Building PySide2

  • Check your Qt installation path, to specifically use that version of qmake to build PySide2:
which qmake
  • 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=/path/to/qmake --build-tests --ignore-git --parallel=8

Installing PySide2

  • To install on the current directory, just run:
python setup.py install --qmake=/path/to/qmake  --openssl=/path/to/openssl --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

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
  • 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 or symbols for Python available. Debug packages can be installed separately in some Linux distributions (e.g.: Ubuntu, the packages python3-dbg, libpython3-dbg provide a debug binary python3-dbg)

If your distribution does not include them, you can download python sources and compile it by yourself, e.g.

./configure --prefix=/where/to/install/python/path CFLAGS="-O0 -fno-inline -fno-omit-frame-pointer -g" LDFLAGS="-O0" CPPFLAGS="-O0" OPT="-O0 -g"
make
make install

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.

A new virtual environment can be created as follows:

virtualenv -p /usr/bin/python3-dbg testenv                                          

Please take into consideration that the binary name might be different in your system, and that you can choose a different name for the environment instead of testenv.

Troubleshooting

  • Wrong RUNPATH / rpath

If you choose to build Python from sources in shared library configuration, it might be the case that the rpath is not set properly, which means that the built python binary might use the system python shared library, instead of the custom build shared library. You can patch the interpreter rpath values with a binary that PySide2 provides:

cd pyside-setup
./patchelf --set-rpath /path/to/your/local/python/lib /path/to/your/python/virtualenv/binary/python

And then you can proceed to re-install PySide2. (you can check if the patch worked with readelf -d /path/to/your/python/virtualenv/binary/python)

  • Missing libICU causes linking problems

From 5.9+ you can get a copy of libICU by specifying --standalone (but not including --iculib-url) as an argument to setup.py execution.

  • Recompile with -fPIC

This issue is usually encountered when using pyenv in a Linux distribution. It's necessary to reinstall python using pyenv with the following addendum:

env PYTHON_CFLAGS=-fPIC pyenv install -v 2.7.8