【发布时间】:2016-05-06 10:34:36
【问题描述】:
这是我按照here 所述安装的:
1. Python 3.5 (Anaconda3 2.4.3)
Chainer 1.5.0.2
Cython 0.23.4
NumPy 1.10.1
tqdm
2. OpenCV 3.0.0
3. lmdb 0.87
4. Boost 1.59.0
接下来我要编译和安装 Boost.NumPy。一开始,找不到 NumPy 模块。经过一番搜索,我在~/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy 中找到了与NumPy 相关的文件,而不是/usr/lib、/usr/local/lib 等。因此,在/Boost.NumPy/CMakeList.txt 中,我添加了这一行:
set(NUMPY_INCLUDE_DIRS, /home/graphics/anaconda3/lib/python3.5/site-packages)
但仍然找不到 NumPy。当我运行 cmake -DPYTHON_LIBRARY=$HOME/anaconda3/lib/libpython3.5m.so ../ 为 Boost.NumPy 生成 makefile 时发生错误。这是错误:
graphics@gubuntu:~/usr/Boost.NumPy/build$ sudo cmake -DPYTHON_LIBRARY=$HOME/anaconda3/lib/libpython3.5m.so ../
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found PythonInterp: /usr/bin/python3.5 (found suitable version "3.5.1", minimum required is "3.5")
-- Found PythonInterp: /usr/bin/python3.5 (found version "3.5.1")
-- Found PythonLibs: /home/graphics/anaconda3/lib/libpython3.5m.so
CMake Error at libs/numpy/cmake/FindNumPy.cmake:61 (message):
NumPy import failure:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'numpy'
Call Stack (most recent call first):
CMakeLists.txt:30 (find_package)
-- Configuring incomplete, errors occurred!
我尝试将NUMPY_INCLUDE_DIRS 替换为其他一些目录,但没有任何效果。我应该写什么到CMakelists.txt 告诉 cmake 在哪里可以找到 NumPy 模块并导入它?
提前致谢!
可能需要找出问题所在的其他文件:
- CMakeLists.txt 的 Boost.NumPy。
【问题讨论】:
-
set()命令中不需要逗号 (,)。此外,最好在cmake调用:cmake -DPYTHON_LIBRARY=<...> -DNUMPY_INCLUDE_DIRS=<...> <source-dir>中设置变量、描述的环境,而不是修改 3d 方 CMake 脚本。 -
@Tsyvarev 谢谢,但在我这样运行后它不起作用:
sudo cmake -DPYTHON_LIBRARY=$HOME/anaconda3/lib/libpython3.5m.so -DNUMPY_INCLUDE_DIRS=$HOME/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy ../。我应该写什么? -
变量
NUMPY_INCLUDE_DIRS为搜索头文件设置目录(在C/C++源代码中)。它不影响 python 模块搜索。您需要设置 PYTHONPATH environment 变量以使事情正常进行。
标签: python numpy cmake anaconda