10

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?

Ron
  • 522
  • 1
  • 3
  • 16

2 Answers2

7

Starting with Nuitka 0.6.2, you can use this code:

is_nuitka = "__compiled__" in globals()
Tiger-222
  • 6,677
  • 3
  • 47
  • 60
  • I wish there were something like sys.pypy_version_info for nuitka. Checking to see if something is compiled isn't necessarily going to continue working as more Python compilers are created. – dstromberg Jun 19 '21 at 23:28
-2

The first idea is to check sys.argv[0] like

if '.exe' in sys.argv[0]:
    # compiled
Pavel M.
  • 610
  • 1
  • 8
  • 24