前提是已经配置好了python的基本使用环境,如numpy等常用moduel的安装. 由于openSUSE自带两个版本的python,一个是python2.7.13一个是python3.4.6,因此之前python环境的配置十分方便. openSUSE虽然自带两个版本的python但是只有一个版本的pip即python3的pip(pip,pip3,pip3.4都是python3的pip) 使用时需要注意,默认使用pip install会安装到python3的sitepackge目录下

1
pip install pycuda

如果没有安装boost-devel与python3-devel可能会有如下错误

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
In file included from bpl-subset/bpl_subset/boost/python/detail/prefix.hpp:13:0,
                     from bpl-subset/bpl_subset/boost/python/args.hpp:8,
                     from bpl-subset/bpl_subset/boost/python.hpp:11,
                     from src/cpp/cuda.hpp:36,
                     from src/cpp/cuda.cpp:1:
    bpl-subset/bpl_subset/boost/python/detail/wrap_python.hpp:75:24: fatal error: patchlevel.h: No such file or directory
     #include <patchlevel.h>
                            ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-kjhruz5r/pycuda/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-2_n06qxu-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-kjhruz5r/pycuda/

安装这两个包即可解决

1
2
zypper in python3-devel
zypper in boost_1_61-devel-1.61.0-4.2.x86_64

注意steuptools也需要安装,要不然可能也会报错

1
2
pip install setuptools/etc/bash.bashrc

下面就可以成功安装pycuda了

1
pip install pycuda

安装好pycuda为了确保能够使用需要安装cuda,以及安装好之后带入环境变量,这里需要注意的是直接在终端使用export导入环境变量只有一段有效时间…可以在目录

1
/etc/bash.bashrc

中加入

1
2
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

然后使用命令使得环境变量生效,但是要立刻使用pycuda的话,电脑需要重启

1
source /etc/bash.bashrc