From 060936fed2ad0bc14251a8703b6139eb7ea62a25 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 16 Apr 2018 10:27:21 +0200 Subject: [PATCH] Detect pybind11 header path without depending on pip internals (fixes #1174) (#1190) --- pybind11/__init__.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/pybind11/__init__.py b/pybind11/__init__.py index a765692fe..5782ffea2 100644 --- a/pybind11/__init__.py +++ b/pybind11/__init__.py @@ -1,11 +1,28 @@ from ._version import version_info, __version__ # noqa: F401 imported but unused -def get_include(*args, **kwargs): +def get_include(user=False): + from distutils.dist import Distribution import os - try: - from pip import locations - return os.path.dirname( - locations.distutils_scheme('pybind11', *args, **kwargs)['headers']) - except ImportError: - return 'include' + import sys + + # Are we running in a virtual environment? + virtualenv = hasattr(sys, 'real_prefix') or \ + sys.prefix != getattr(sys, "base_prefix", sys.prefix) + + if virtualenv: + return os.path.join(sys.prefix, 'include', 'site', + 'python' + sys.version[:3]) + else: + dist = Distribution({'name': 'pybind11'}) + dist.parse_config_files() + + dist_cobj = dist.get_command_obj('install', create=True) + + # Search for packages in user's home directory? + if user: + dist_cobj.user = user + dist_cobj.prefix = "" + dist_cobj.finalize_options() + + return os.path.dirname(dist_cobj.install_headers)