Hint PyCharm that an object is defined

Hello,

I have the following bit of code in Python:

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


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!
0
2 comments
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.
0
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.
0

Please sign in to leave a comment.