PyCharm Debugging

In order to debug the server using PyCharm you need to do two things:

  1. Create new remote Python interpreter
  2. Create a debug configuration

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.
  2. Choose the docker-compose.yml at the root of your Phovea workspace
  3. Set the service to the docker container you would like to debug.
  4. 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
  2. Select project directory and specify it is located at /phovea
  3. In the end the overview page should state: <Project root> -> /phovea
  4. Gevent compatible Python debugging
  5. Go to Build, Execution, Deployment -> Python Debugger
  6. Check Gevent compatible
  7. Uncheck PyQt compatible
  8. Apply changes -> Close settings dialog

Pycharm Python new Docker Server using Unix Socket

Pycharm Python Interpreter

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.
  2. Choose the docker-compose.yml at the root of your Phovea workspace
  3. Set the service to the docker container you would like to debug.
  4. 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
  2. Select project directory and specify it is located at /phovea
  3. In the end the overview page should state: <Project root> -> /phovea
  4. Gevent compatible Python debugging
  5. Go to Build, Execution, Deployment -> Python Debugger
  6. Check Gevent compatible
  7. Uncheck PyQt compatible
  8. Apply changes -> Close settings dialog

Pycharm Python Remote Interpreter

Pycharm Python Debugger

Create a phovea_server debug launch configuration

PyCharm might have already created that one for you, otherwise:

  1. Run -> Edit Configurations
  2. 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)
  • 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

Run the server using PyCharm

  1. Only if you are debugging via SSH then: Start Docker using the debug mixin
  2. Set a breakpoint next to the line number in a Python file
  3. Run -> Debug -> phovea_server
  4. Open the URL in the browser that triggers the breakpoint
  5. Debug the Python in the PyCharm panel

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