Skip to content

Commit b2f944f

Browse files
committed
Detect pybind11 header path without depending on pip internals (fixes #1174)
1 parent 6d19036 commit b2f944f

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

pybind11/__init__.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
from ._version import version_info, __version__ # noqa: F401 imported but unused
22

33

4-
def get_include(*args, **kwargs):
4+
def get_include(user=False):
5+
from distutils.dist import Distribution
56
import os
6-
try:
7-
from pip import locations
8-
return os.path.dirname(
9-
locations.distutils_scheme('pybind11', *args, **kwargs)['headers'])
10-
except ImportError:
11-
return 'include'
7+
import sys
8+
9+
# Are we running in a virtual environment?
10+
virtualenv = hasattr(sys, 'real_prefix') or \
11+
sys.prefix != getattr(sys, "base_prefix", sys.prefix)
12+
13+
if virtualenv:
14+
return os.path.join(sys.prefix, 'include', 'site',
15+
'python' + sys.version[:3], 'pybind11')
16+
else:
17+
dist = Distribution({'name': 'pybind11'})
18+
dist.parse_config_files()
19+
20+
dist_cobj = dist.get_command_obj('install', create=True)
21+
22+
# Search for packages in user's home directory?
23+
if user:
24+
dist_cobj.user = user
25+
dist_cobj.prefix = ""
26+
dist_cobj.finalize_options()
27+
28+
return dist_cobj.install_headers

0 commit comments

Comments
 (0)