1
2
3
4
git clone https://github.com/stevengj/nlopt.git 
cd nlopt
mkdir build
cd build
1
2
3
# 安装 SWIG(用于生成 Python 绑定)
sudo apt-get update
sudo apt-get install swig
1
2
3
4
5
6
7
8
cmake .. \
-DNLOPT_PYTHON=ON \
-DPython_EXECUTABLE=$(which python) \
-DPython_NumPy_INCLUDE_DIRS=$(python -c "import numpy; print(numpy.get_include())")

make

sudo make install
1
2
# 查看是否生成了 Python 相关文件
find . -name "*python*" -o -name "*.py" -o -name "*.so"
1
2
3
4
5
6
7
8
# 进入 Python 绑定目录
cd src/swig/python

# 查看目录内容
ls -la

# 安装 Python 绑定
pip install .