How to check if idapythonrc.py is running in IDA Pro or idalib?

This depends on whether you need to detect only “not IDA GUI”, or specifically “idalib context”, since you can also have idat, or a separate Python process.