python - 编译Boost.Numpy时CMake错误 "NumPy import failure"

标签 python numpy cmake anaconda

这是我按照描述安装的 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 模块并导入它?

提前致谢!

<小时/>

可能需要找出问题所在的其他文件:

  1. CMakeLists.txt Boost.NumPy。

最佳答案

终于可以用了!但我不知道为什么...:(

我做了什么:

1.  I reinstalled numpy to /usr/lib/python3.5/site-packages (previously, I installed it to ~/anaconda3/lib/python3.4/site-packages)
1.1 I also added ~/anaconda3/lib/python3.4/site-packages/numpy/include to $PYTHONPATH and $PATH
2.  I ran these commands in Python:
   >>>import numpy 
   And I found it returns no error!
3.  I removed previously compiled files in directory build, and rebuilt. Finally it worked

希望这些对其他人有帮助。

关于python - 编译Boost.Numpy时CMake错误 "NumPy import failure",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37070210/

相关文章:

python - 对数时间Python中有序列表中的位置元素

python - Numpy,避免3d数组差异嵌套求和中的循环

NumPy 数组看起来很慢;难道我做错了什么?

cmake - 错误的 CMAKE_BINARY_DIR?

c++ - 如何解决 gRPC 生成文件中的编译错误?

python - 如何使全局变量从数据库中刷新

python - concurrent.futures 问题 : why only 1 worker?

cmake - 如何使我的单元测试适应 cmake 和 ctest?

python - Python multiprocessing.Queue 线程安全吗?

python - numpy.recarray.tobytes 的逆