0

I'm developing python plugins for CheckMK in Pycharm and I'm using a remote interpreter. Within my code I have import statements which looks like this:

from .agent_based_api.v1 import Service

To make that work in PyCharm I used a bash script to add something to the PYTHONPATH:

#!/bin/bash
# Set system variable to run subscription manager
export PYTHONPATH=/opt/omd/versions/2.0.0p15.cme/lib/python3/cmk/base/plugins/agent_based/

# Run python with arguments
/opt/omd/versions/2.0.0p15.cme/bin/python3 $@

This works somehow, but now I need to write this:

from agent_based_api.v1 import Service

(without the dot) to make PyCharm discover the module correctly.

How can I have that import work with the dot?

Cheers, Roland.

R. Gsell
  • 117
  • 1
  • 6
  • If you look at [the import syntax](https://docs.python.org/3/reference/import.html#package-relative-imports) carefully, in the 1st example you are doing a relative import from the package that module is currently in. Now, in the 2nd example you want to omit the relative path to write a shortened import. You have 2 choices here: either [expose the module in the `__init__.py`](https://docs.python.org/3/reference/import.html#submodules) of the package, or use the IDE and mark the path containing the package as [sources root](https://stackoverflow.com/a/21241988). – bad_coder Nov 09 '21 at 10:39
  • To avoid [circular imports](https://stackoverflow.com/questions/7336802) further up the road you are well advised to use fully qualified names everywhere. – bad_coder Nov 09 '21 at 10:42

0 Answers0