PyCharm Professional

The official documentation on configuring a docker interpreter is pretty complete, but there are caveats. Below, you will find an improved configuration guide helping you to set up the runtime quickly.

The guide tested with PyCharm 2023.1.4 Professional.

Note

If you have a different version of PyCharm, we cannot guarantee that the settings will work and match the screenshots.

Project Preparation

  1. Clone the repo:

    git clone https://github.com/insight-platform/Savant.git
    
  2. Copy and rename the template (let’s name the new project my-module):

    cp -r Savant/samples/template my-module
    
  3. Start the IDE and create a new project in the my-module directory.

  4. When creating a project, select the system Python interpreter

Setting Up The Interpreter for the Module

  1. Open the project settings with File > Settings … or Ctrl+Alt+S. Set Use compose V2 in Build, Execution,Deployment > Docker > Tools

  2. Open the project settings with File > Settings … or Ctrl+Alt+S.

  3. Select Project: my-module > Python Interpreter section.

  4. Add a new Python Interpreter by clicking the Add Interpreter, and selecting On Docker Compose…:

  5. In the modal window:

    1. Click on the three dots under Server and set up access to the docker service

    2. Select Configuration file: docker-compose.x86.yml (docker-compose.l4t.yml for Jetson) and select the service module:

    3. Click Next button, make sure docker build is successful and then again click Next button.

    4. Keep the default python interpreter (python3) and click Create:

  6. Make sure that the savant package is in the package list, click OK:

Setting Up The Interpreter for the Client

  1. Add Python Interpreter by clicking the Add Interpreter, and selecting On Docker Compose…:

  2. In the modal window:

    1. Select Configuration file: docker-compose.x86.yml (docker-compose.l4t.yml for Jetson) and select the service client:

    2. Click Next button, make sure docker build is successful and then again click Next button.

    3. Keep the default python interpreter (python3) and click Create:

Configure Module Run

The module/run.py file is the entrypoint of the module, let’s configure the launch command for the script.

  1. Open the module/run.py script

  2. Right click of mouse on the tab module/run.py and select Modify Run Configuration in “”More Run/Debug:

  3. In the Environment section add PYTHONPATH=/opt/savant (PyCharm rewrites PYTHONPATH), select Docker compose(module) interpreter. If you used a custom Dockerfile, you need to set up --build module in Docker Compose > Command and options.

  4. Launch the module by selecting Run ‘run’ or with the hotkey Ctrl+Shift+F10:

  5. You may see various GStreamer error messages: it’s ok. At the end you will see the output module status to ModuleStatus.RUNNING.:

Configure Client Run

The client/run.py This is a script that allows you to interact with the module by sending data and receiving results. Let’s configure the launch command for the script.

  1. Open the client/run.py script

  2. Right click of mouse on the tab client/run.py and select Modify Run Configuration in “”More Run/Debug:

  3. In the Environment section add PYTHONPATH=/opt/savant (PyCharm rewrites PYTHONPATH) and select Docker compose(client) interpreter:

  4. Launch the client script by selecting Run ‘run client’ or with the hotkey Ctrl+Shift+F10:

  5. Check the results:

    • Open output/result_img.jpeg in the IDE Explorer to see the result image.

    • Visit http://127.0.0.1:16686 to access the Jaeger UI.

That’s it, the environment is set up. Now you are ready to develop your own pipeline. See the next section to find out how.

Update Runtime On Container Change

Changes to the Dockerfile or the base image

If you used a custom Dockerfile you should check that the up --build module option is set in the Run configuration settings. If this option is set and you have made any changes to the Dockerfile or updated the base image, you don’t need to do anything else. At the next run a new image will be built and the container will be updated.

Adding new packages to requirements.txt

Once dependencies are added to the requirements.txt, they will be automatically installed when building a new image.

However, PyCharm does not automatically detect newly installed packages in the Docker container. The PyCharm will update the skeleton at the next startup or you can manually scan for new packages. To do this, you need to open the Settings and look for Rescan, then navigate to Plugins > Python > Rescan Available Python Modules and Packages and set the hotkey (e.g., Alt+R):

After adding a new package to the requirements.txt, simply press the specified hotkey to rebuild the image and update the packages.

In the following sections, you will find additional details on module development.