我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用distutils.sysconfig.get_python_inc()。
def test_get_python_inc(self): inc_dir = sysconfig.get_python_inc() # This is not much of a test. We make sure Python.h exists # in the directory returned by get_python_inc() but we don't know # it is the correct file. self.assertTrue(os.path.isdir(inc_dir), inc_dir) python_h = os.path.join(inc_dir, "Python.h") self.assertTrue(os.path.isfile(python_h), python_h)
def __init__(self): """ Initialise the configuration. """ self.platform = sys.platform self.version = sys.hexversion >> 8 self.inc_dir = sysconfig.get_python_inc() self.venv_inc_dir = sysconfig.get_python_inc(prefix=sys.prefix) self.module_dir = sysconfig.get_python_lib(plat_specific=1) if sys.platform == 'win32': self.bin_dir = sys.exec_prefix self.data_dir = sys.prefix self.lib_dir = sys.prefix + '\\libs' else: self.bin_dir = sys.exec_prefix + '/bin' self.data_dir = sys.prefix + '/share' self.lib_dir = sys.prefix + '/lib' # The name of the interpreter used by the pyuic5 wrapper. if sys.platform == 'darwin': # The installation of MacOS's python is a mess that changes from # version to version and where sys.executable is useless. py_major = self.version >> 16 py_minor = (self.version >> 8) & 0xff # In Python v3.4 and later there is no pythonw. if (py_major == 3 and py_minor >= 4) or py_major >= 4: exe = "python" else: exe = "pythonw" self.pyuic_interpreter = '%s%d.%d' % (exe, py_major, py_minor) else: self.pyuic_interpreter = sys.executable
def python_config (self): cflags = self._getitem('default', 'python_cflags', None) ldflags = self._getitem('default', 'python_ldflags', None) if cflags or ldflags: return (cflags.strip('\r\n\t '), ldflags.strip('\r\n\t ')) pythoninc, pythonlib = [], [] import distutils.sysconfig sysconfig = distutils.sysconfig inc1 = sysconfig.get_python_inc() inc2 = sysconfig.get_python_inc(plat_specific = True) pythoninc.append('-I' + self.pathtext(inc1)) if inc2 != inc1: pythoninc.append('-I' + self.pathtext(inc2)) pyver = sysconfig.get_config_var('VERSION') getvar = sysconfig.get_config_var if not pyver: v1, v2 = sys.version_info[:2] pyver = self.unix and '%s.%s'%(v1, v2) or '%s%s'%(v1, v2) lib1 = getvar('LIBS') pythonlib.extend(lib1 and lib1.split() or []) prefix = sys.prefix if os.path.exists(prefix): if not pythoninc: n1 = os.path.join(prefix, 'include/python%s'%pyver) n2 = os.path.join(prefix, 'include') if os.path.exists(n1 + '/Python.h'): pythoninc.append('-I' + self.pathtext(n1)) elif os.path.exists(n2 + '/Python.h'): pythoninc.append('-I' + self.pathtext(n2)) if not pythonlib: n1 = os.path.join(prefix, 'lib/python%s'%pyver) n2 = os.path.join(n1, 'config') n3 = os.path.join(prefix, 'libs') fn1 = 'libpython' + pyver + '.a' fn2 = 'libpython' + pyver + '.dll.a' done = False for ff in (fn1, fn2): for nn in (n1, n2, n3): if os.path.exists(nn + '/' + ff): pythonlib.append('-L' + self.pathtext(nn)) done = True break if done: break lib2 = getvar('SYSLIBS') pythonlib.extend(lib2 and lib2.split() or []) if not getvar('Py_ENABLE_SHARED'): if getvar('LIBPL'): pythonlib.insert(0, '-L' + getvar('LIBPL')) if not getvar('PYTHONFRAMEWORK'): if getvar('LINKFORSHARED'): pythonlib.extend(getvar('LINKFORSHARED').split()) pythonlib.append('-lpython' + pyver) cflags = ' '.join(pythoninc) ldflags = ' '.join(pythonlib) return cflags, ldflags # ???? java??