Hint PyCharm that an object is defined


I have the following bit of code in Python:

sys.path.append(os.path.join(sys.path[0], "..", "..", "getdsip"))
    from getdsip import GetDSIP
    print("ERROR: cannot load GetDSIP")

Since getdsip is not visible by the interpreter before runtime it gets tagged as an unknown module by PyCharm. Is there a way to "hint" the IDE that this module does indeed exist and therefore no warning should be issued?

This question could be extended: if the import statement was from getdsip import * then any class name would be unknown to the IDE (and it would be good to be able to "hint" it as per above)

Thank you!
You can add your /path/to/getdsip to Settings|Project Interpreter|Python Interpreters|Paths.

Note that you can tweak your PYTHONPATH instead of modifying sys.path in your code.
Fantastic - thank you!

As for PYTHONPATH: the location of the module will be different between systems - the only thing which is required is that it is ".." relative to the script directory. I dod not found a better way to handle this in the code.

Please sign in to leave a comment.