how to inform PyCharm that a module is indeed imported?

Hello,

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": "http://docs.python-requests.org/en/latest/user/install/#install or aptitude install python-requests",
    "simplejson": "https://github.com/simplejson/simplejson or aptitude install python-simplejson"
}
missingmodules = []
for k, v in extramodules.iteritems():
    try:
        globals()[k] = importlib.import_module(k)
    except:
        missingmodules.append(k)
if missingmodules:
    for k in missingmodules:
        print "MISSING MODULE {}, see {}".format(k,extramodules[k])
    print "ABORTING, need to install missing modules above"
    sys.exit(1)
prettyPrint();

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
0

Please sign in to leave a comment.