// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \page creator-python-development.html \previouspage creator-copilot.html \nextpage creator-mime-types.html \title Developing Qt for Python Applications \l {https://doc.qt.io/qtforpython/index.html}{Qt for Python} enables you to use Qt 6 API in Python applications. You can use the PySide6 modules to gain access to individual Qt modules, such as \l {Qt Core}, \l {Qt GUI}, and \l {Qt Widgets}. The following sections describe using \QC for developing with Qt for Python: \list \li \l{Creating Widget-Based Qt for Python Applications} {Creating Qt for Python Applications} \li \l{Setting Up PySide6} \li \l{Selecting the Python Interpreter} \li \l{Creating a Virtual Environment} \li \l{Using Python Interactive Shell} \li \l{Python Language Server} \li \l{Running Python Projects} \li \l{Specifying Run Settings for Python Projects} \li \l{PDB} \li \l{Launching the Debugger} \endlist For more information about developing with Qt for Python, including limitations, see \l {https://doc.qt.io/qtforpython/index.html} {Qt for Python}. \section1 Setting Up PySide6 If you have not installed the required version of PySide6, \QC prompts you to do so when you open a .py file. \image qtcreator-python-install.webp {Prompts to install PySide6 and Python language server} Further, \QC prompts you to install the \l {Python Language Server} {Python language server} that offers services such as code completion and annotations. Select \uicontrol Install to install PySide6 and the language server. \section1 Selecting the Python Interpreter You select the initial Python interpreter when you use the Qt for Python Application wizard templates to create Python projects. \image qtcreator-python-wizard-define-python-interpreter.webp {Define Python Interpreter wizard page} You can see the current Python interpreter on the \uicontrol Edit mode toolbar. \image qtcreator-python-interpreter-edit-mode.webp {Python interpreter on the Edit mode toolbar} You can change the interpreter to use for a particular project in \uicontrol Projects > \uicontrol Run > \uicontrol Interpreter. \image qtcreator-python-run-settings.png {Python run settings} To see the available interpreters and choose another interpreter, select the current interpreter, and then select \uicontrol {Manage Python Interpreters}. Or, select \uicontrol Edit > \uicontrol Preferences > \uicontrol Python > \uicontrol Interpreters. \image qtcreator-python-interpreters.png {Python Interpreters in Preferences} You can add and remove interpreters and clean up references to interpreters that you uninstalled, but that still appear in the list. In addition, you can set the interpreter to use by default. \section1 Creating a Virtual Environment To create a virtual environment (\c venv) when you use the Qt for Python Application wizard templates to create Python projects, select the \uicontrol {Create new virtual environment} check box on the \uicontrol {Define Python Interpreter} wizard page. Specify the directory where to create the environment in \uicontrol {Path to virtual environment}. \section1 Using Python Interactive Shell You can write Python code in the Edit mode. Select \uicontrol REPL on the toolbar to start the \l{https://pythonprogramminglanguage.com/repl/} {Python interactive shell} in the \l Terminal pane. \image qtcreator-terminal-python.webp {Python shell on the taskbar} To start the shell and import the current file as a module, select \uicontrol {REPL Import File}. To also import all functions from the file, select \uicontrol {REPL Import *}. */