Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically detect if code is running in nuitka compiled or python interpreted mode

Tags:

python

nuitka

Can anyone say how to detect if code is running in an exe created by Nuitka or in a normal python interpreter?

I think I would ideally like an "is_nuitka" flag that would be set to True when compiled and presumably not exist at all when not compiled.

Could then use code like this:

if '__is_nuitka__' in locals() or '__is_nuitka__' in globals():
    print('debug info: running in nuitka mode')

Any suggestions? Is there anything like this available? any alternative approaches?

like image 750
Ron Avatar asked Aug 12 '16 10:08

Ron


1 Answers

Starting with Nuitka 0.6.2, you can use this code:

is_nuitka = "__compiled__" in globals()
like image 57
Tiger-222 Avatar answered Oct 19 '22 20:10

Tiger-222