The PyCharm console Python actually launches a module called pydevconsole.py (should be located in the C: \ Program Files \ JetBrains \ PyCharm 2017.1.2 \ helpers \ pydev \ pydevconsole.py folder). This module creates an interpreter and sets it as an attribute of the builtins module.
Thus, print(__name__) in the PyCharm console will display builtins .
At run time (when you click run), your Python interpreter is called, not the pydevconsole module. therefore print(__name__) shows __main__ as expected.
source share