<!-- TITLE: PyCharm Debugging --> In order to debug the server using [PyCharm](https://www.jetbrains.com/pycharm/download) you need to do two things: 1. [Create new remote Python interpreter](#create-remote-python-interpreter) 1. [Create a debug configuration](#create--python-debug-conf) <a id="create-remote-python-interpreter"></a> ## Create new remote Python interpreter (new Tutorial) **Prerequisites** 1. Docker compose and SSH Credentials are only available as options for a new Project Interpreter in PyCharm Professional (does not work with PyCharm Community!). 2. ptvsd cannot be installed, if you want to debug with PyCharm (pydevd does not work with ptvsd installed). **1. Add a Python Interpreter** Within PyCharm go to Settings -> Project Interpreter -> Cogs symbol -> Add... At the time of this writing there are multiple options, we will explain Docker Compose, because SSH Credentials don't work with Python 3.7. **2. Using Docker compose** Select Docker Compose and check the following values: 1. Create a new Docker Server using Unix socket. 1. Choose the `docker-compose.yml` at the root of your Phovea workspace 1. Set the service to the docker container you would like to debug. 1. Make sure the python interpreter is set to `python`. **3. Further actions** PyCharm should now be able to connect to the docker container and upload some helper files. 1. Create default path mappings 1. Select project directory and specify it is located at `/phovea` 1. In the end the overview page should state: `<Project root> -> /phovea` 1. Gevent compatible Python debugging 1. Go to *Build, Execution, Deployment* -> *Python Debugger* 1. Check `Gevent compatible` 1. Uncheck `PyQt compatible` 1. Apply changes -> Close settings dialog ![Pycharm Python new Docker Server using Unix Socket](/uploads/images/pycharm-debug-unix-1.png "Create a new Docker Server using Unix Socket") ![Pycharm Python Interpreter](/uploads/images/pycharm-interpreter-2.png "Pycharm Python Interpreter") ![Pycharm Python Debugger](/uploads/images/pycharm-debugger-3.png "Pycharm Python Debugger") ## [OUTDATED] Create new remote Python interpreter **1. Add a Python Interpreter** Within PyCharm go to Settings -> Project Interpreter -> Cogs symbol -> Add... At the time of this writing there are multiple options, we will explain two of it: Docker Compose and SSH Credentials. **2a. Using Docker compose (recommended)** Select Docker Compose and check the following values: 1. Create a new Docker Server using Unix socket. 1. Choose the `docker-compose.yml` at the root of your Phovea workspace 1. Set the service to the docker container you would like to debug. 1. Make sure the python interpreter is set to `python`. **2b. Using SSH Credentials** Select SSH-Credentials and use the following values: * Host: `localhost` * Port: `2222` * User name: `root` * Password: `docker` * Python interpreter path: `/usr/local/bin/python` **NOTE: this is different from the default!** **3. Regardless of chosen option** PyCharm should now be able to connect to the docker container and upload some helper files. Regardless of which option you chose: 1. Create default path mappings 1. Select project directory and specify it is located at `/phovea` 1. In the end the overview page should state: `<Project root> -> /phovea` 1. Gevent compatible Python debugging 1. Go to *Build, Execution, Deployment* -> *Python Debugger* 1. Check `Gevent compatible` 1. Uncheck `PyQt compatible` 1. Apply changes -> Close settings dialog ![Pycharm Python Remote Interpreter](/uploads/images/pycharm-python-remote-interpreter.png "Pycharm Python Remote Interpreter") ![Pycharm Python Debugger](/uploads/images/pycharm-python-debugger.png "Pycharm Python Debugger") <a id="create--python-debug-conf"></a> ## Create a phovea_server debug launch configuration PyCharm might have already created that one for you, otherwise: 1. *Run* -> *Edit Configurations* 1. In the dialog *Plus sign* (top-left) -> Python * Name: `phovea_server` * Script: `\phovea\phovea_server\__main__.py` * Script parameters: `--env=dev api` * Python interpreter: Remote Python ([created above](#create-remote-python-interpreter)) * Working directory: `\phovea` * Uncheck `Add content roots to PYTHONPATH` and `Add source roots to PYTHONPATH` 1. Apply and close the dialog ![Pycharm Debug Launch Config](/uploads/images/pycharm-run-debug-config.png "Pycharm Debug Launch Config") ## Run the server using PyCharm 1. Only if you are debugging via SSH then: [Start Docker using the debug mixin](#prepare-environment) 1. Set a breakpoint next to the line number in a Python file 1. *Run* -> *Debug* -> *phovea_server* 1. Open the URL in the browser that triggers the breakpoint 1. Debug the Python in the PyCharm panel <a id="prepare-environment"></a> ### Prepare environment Restart Docker with the debug mixin ``` ./docker-compose-debug up ``` Restart Docker in the *normal-mode* to exit the debug-mode: ``` docker-compose up ```