-python = find_program('python3')
-pythondetector = find_program('pythondetector')
-py_so_suffix = run_command(pythondetector, '--sosuffix').stdout().strip()
-pygi_override_dir = run_command(pythondetector, '--pygi-overridedir').stdout().strip()
-python_abi_flags = run_command(pythondetector, '--abiflags').stdout().strip()
-pylib_loc = run_command(pythondetector, '--libloc').stdout().strip()
-assert(pylib_loc != 'None', 'Python dynamic library path could not be determined')
+pymod = import('python')
+python = pymod.find_installation(get_option('python'))
+python_dep = python.dependency(required : true)
+
+python_abi_flags = python.get_variable('ABIFLAGS', '')
+pylib_loc = python.get_variable('LIBPL', '')
+if host_machine.system() != 'windows'
+ assert(pylib_loc != '', 'Python dynamic library path could not be determined')
+endif
+message('python_abi_flags = @0@'.format(python_abi_flags))
+message('pylib_loc = @0@'.format(pylib_loc))
+
+pygi_override_dir = get_option('pygi-overrides-dir')
+if pygi_override_dir == ''
+ cres = run_command(python, '-c','''
+import os, sys, gi.overrides
+paths = gi.overrides.__path__
+prefix = os.path.abspath(sys.argv[1])
+for path in paths:
+ path = os.path.abspath(path)
+ if os.path.commonprefix([path, prefix]) == prefix:
+ print(path)
+ exit(0)
+exit(1)
+''', get_option('prefix'))
+
+ if cres.returncode() != 0
+ error('Could not detect PyGObject overrides location' + cres.stdout() + cres.stderr())
+ endif
+ pygi_override_dir = cres.stdout().strip()
+ if cres.stderr() != ''
+ message(cres.stderr())
+ endif
+endif
+message('pygobject overrides directory = @0@'.format(pygi_override_dir))