python – How do code modules and package modules change in a conda environment?
This stackoverflow post explains the difference between running files with import <modulename>
, python <filename>
, and python -m <modulename>
:
Module execution via import statement (i.e., import <modulename>):
sys.path is not modified in any way
__name__ is set to the absolute form of <modulename>
__package__ is set to the immediate parent package in <modulename>
__init__.py is evaluated for all packages (including its own for package modules)
__main__.py is not evaluated for package modules; the code is evaluated for code modules
Module execution via command line with filename (i.e., python <filename>):
sys.path is modified to include the final directory in <filename>
__name__ is set to '__main__'
__package__ is set to None
__init__.py is not evaluated for any package (including its own for package modules)
__main__.py is evaluated for package modules; the code is evaluated for code modules.
Module execution via command line with modulename (i.e., python -m <modulename>):
sys.path is modified to include the current directory
__name__ is set to '__main__'
__package__ is set to the immediate parent package in <modulename>
__init__.py is evaluated for all packages (including its own for package modules)
__main__.py is evaluated for package modules; the code is evaluated for code modules
However, I was curious how the __name__
, __package__
, __init__.py
, and __main__.py
change when running these commands are run in a conda environment?
Read more here: Source link