""" Modules that have been loaded as an argument to the command line cannot be reloaded using importlib.reload. # following works fine: $ python -c "import reloader; reloader.reload_module('reloader')" # if the module is the argument to python, it cannot be reloaded $ python reloader.py Traceback (most recent call last): File "reloader.py", line 31, in reload_module("__main__") File "reloader.py", line 28, in reload_module importlib.reload(module) File "/usr/local/var/pyenv/versions/3.5.2/lib/python3.5/importlib/__init__.py", line 166, in reload _bootstrap._exec(spec, module) File "", line 607, in _exec AttributeError: 'NoneType' object has no attribute 'name' """ import sys import importlib def reload_module(name): module = sys.modules[name] importlib.reload(module) if __name__ == "__main__": reload_module("__main__")