我正在尝试在macOS 10.15.5上安装nlopt。我从NLopt docs下载了nlopt-2.6.2.tar.gz file,并从nlopt-2.6.2目录运行以下命令:
mkdir build
cd build
cmake -DNLOPT_OCTAVE=Off -DNLOPT_MATLAB=Off -DNLOPT_GUILE=Off ..
make
sudo make install我得到了以下输出:cmake.txt。
头文件(nlopt.h)正确安装到/usr/local/include,动态库(libnlopt.dylib)正确安装到/usr/local/lib/,但是dist-info文件和nlopt模块本身都没有安装。
我也尝试过通过pip、brew和conda进行安装,但都没有成功。我也尝试过从这个Github中克隆,但也不起作用。
我很感谢大家的帮助,因为我完全迷失了方向。我对这类东西比较陌生,在网上找不到任何好的答案。
发布于 2020-07-04 00:25:03
官方文档对使用Python绑定构建nlopt所需的确切步骤有些简洁。首先,你需要安装SWIG:
$ brew install swig然后,您将需要numpy可用于目标Python解释器。它已经为system Python预先安装,或者通过Homebrew或pip安装,具体取决于您的Python安装。
现在运行cmake
$ cmake -DNLOPT_GUILE=OFF -DNLOPT_MATLAB=OFF -DNLOPT_OCTAVE=OFF -DNLOPT_TESTS=OFF这将针对MacOS上预装的默认Python2.7安装构建绑定。如果您需要基于自定义Python安装进行构建(例如,当您通过Homebrew或来自https://www.python.org/downloads的PKG安装程序安装Python3时),请通过PYTHON_EXECUTABLE arg:
$ cmake -DNLOPT_GUILE=OFF -DNLOPT_MATLAB=OFF -DNLOPT_OCTAVE=OFF -DNLOPT_TESTS=OFF -DPYTHON_EXECUTABLE=/usr/local/bin/python3现在检查日志- Python、SWIG和numpy标头应该被成功定位。示例输出片段(您可能打印了不同的路径/版本):
-- Found PythonInterp: /usr/local/bin/python3.8 (found version "3.8.3")
-- Found PythonLibs: /Library/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib (found suitable exact version "3.8.3")
-- Found NumPy: /Users/hoefling/Library/Python/3.8/lib/python/site-packages/numpy/core/include (found version "1.19")
-- Found SWIG: /usr/local/bin/swig (found version "4.0.2")如果不满足这些条件中的任何一个(例如,您看到Could NOT find NumPy、Could NOT find PythonLibs或Could NOT find SWIG),则停止并确保配置成功,然后再继续下一步。
现在编译:
$ make
...
Scanning dependencies of target nlopt_python_swig_compilation
[ 96%] Swig compile nlopt.i for python
[ 96%] Built target nlopt_python_swig_compilation
Scanning dependencies of target nlopt_python
[ 98%] Building CXX object src/swig/CMakeFiles/nlopt_python.dir/CMakeFiles/nlopt_python.dir/nloptPYTHON_wrap.cxx.o
[100%] Linking CXX shared module _nlopt.so
[100%] Built target nlopt_python安装:
$ make install
...
-- Installing: /usr/local/lib/python3.8/site-packages/nlopt.py
-- Installing: /usr/local/lib/python3.8/site-packages/_nlopt.so测试Python绑定是可导入的:
$ python -c "import nlopt; print(nlopt.__version__)"
2.6.2https://stackoverflow.com/questions/62704802
复制相似问题