how to inform PyCharm that a module is indeed imported?


In order to account for exotic modules in a script (exotic = modules that a user may not have) I do not import them straight away but rather use a more friendly approach (see second comment in this Stack Overflow question of mine for details).

import sys, importlib
extramodules = {
    "requests": " or aptitude install python-requests",
    "simplejson": " or aptitude install python-simplejson"
missingmodules = []
for k, v in extramodules.iteritems():
        globals()[k] = importlib.import_module(k)
if missingmodules:
    for k in missingmodules:
        print "MISSING MODULE {}, see {}".format(k,extramodules[k])
    print "ABORTING, need to install missing modules above"

PyCharm rightfully raises an error when using a module which seems not to be imported, even though it (indirectly) is. Is there a way to inform PyCharm that some modules should not be reported as missing? (or, worst case, disable this particular error – which I would like to avoid)

Thank you!
1 comment
Comment actions Permalink
Hi WoJ,
you can do that: just invoke alt+enter quick-fix and there in menu 'Mark all unresolved attributes as ignored' you can a) Select 'Edit inspection profile settings' and add your import to Ignore references list b) Suppress it for statement

Please sign in to leave a comment.