I am trying to get the startup banner info in Python, not just:
f'''Python {sys.version} on {sys.platform}
Type "help", "copyright", "credits", or "license" for more information.'''
which results in:
Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
but the full startup banner including any errors and the distribution for example:
Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation.
Type "help", "copyright", "credits" or "license" for more information.
I was thinking of running python
in subprocess.Popen
and then terminate it, but I have not been able to capture the startup banner output.
I was finally able to figure this question out. Turns out
subprocess.Popen
was the right answer. Interestingly the header was printed tostderr
instead ofstdout
. Code that worked for me: