這裏的時候是我所描述的here安裝:CMake的錯誤「NumPy的導入失敗」編譯Boost.Numpy
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的生成文件時發生錯誤。以下是錯誤:
[email protected]:~/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模塊並導入它?
在此先感謝!
這可能需要找出什麼不順心其他文件:
- Boost.NumPy的CMakeLists.txt。
逗號('')不需要在'()設置。 ',而不是修改3D方CMake腳本,最好在'cmake'調用中設置變量,描述環境:'cmake -DPYTHON_LIBRARY = <...> -DNUMPY_INCLUDE_DIRS = <...>'。 –
Tsyvarev
@Tsyvarev謝謝,但它運行後不起作用:'sudo cmake -DPYTHON_LIBRARY = $ HOME/anaconda3/lib/libpython3.5m.so -DNUMPY_INCLUDE_DIRS = $ HOME/anacon da3/lib/python3.5/site-packages/numpy/core/include/numpy ../'。我應該寫什麼? – Anonymous
變量'NUMPY_INCLUDE_DIRS'爲搜索**頭文件**(在C/C++源文件中)設置目錄。它不影響python模塊搜索。您需要設置[PYTHONPATH](https://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH)* environment *變量才能使事情順利進行。 – Tsyvarev