Skip to content

Commit cb402f9

Browse files
authored
Merge pull request #44 from Tieqiong/setup
fix: py3.11 can't find boost
2 parents 5f34e62 + d0a96e8 commit cb402f9

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Diff for: setup.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
"""
88

99
import glob
10+
import os
1011
import sys
1112
from ctypes.util import find_library
13+
from pathlib import Path
1214

1315
import numpy
1416
from setuptools import Extension, setup
@@ -26,11 +28,33 @@ def get_boost_libraries():
2628
raise RuntimeError("Cannot find a suitable Boost.Python library.")
2729

2830

31+
def get_boost_config():
32+
boost_path = os.environ.get("BOOST_PATH", "")
33+
if boost_path:
34+
inc = Path(boost_path) / "include"
35+
lib = Path(boost_path) / "lib"
36+
else:
37+
conda_prefix = os.environ.get("CONDA_PREFIX")
38+
if not conda_prefix:
39+
raise EnvironmentError(
40+
"Neither BOOST_PATH nor CONDA_PREFIX are set. " "Please install Boost or set BOOST_PATH."
41+
)
42+
if os.name == "nt":
43+
inc = Path(conda_prefix) / "Library" / "include"
44+
lib = Path(conda_prefix) / "Library" / "lib"
45+
else:
46+
inc = Path(conda_prefix) / "include"
47+
lib = Path(conda_prefix) / "lib"
48+
return {"include_dirs": [str(inc)], "library_dirs": [str(lib)]}
49+
50+
51+
boost_cfg = get_boost_config()
2952
ext_kws = {
3053
"libraries": ["diffpy"] + get_boost_libraries(),
3154
"extra_compile_args": ["-std=c++11"],
3255
"extra_link_args": [],
33-
"include_dirs": [numpy.get_include()],
56+
"include_dirs": [numpy.get_include()] + boost_cfg["include_dirs"],
57+
"library_dirs": boost_cfg["library_dirs"],
3458
}
3559

3660

0 commit comments

Comments
 (0)