ImportError : No module named pygpu

4 篇文章 0 订阅
1 篇文章 0 订阅

用python执行以下例子的时候:(测试theano调用gpu执行程序)http://deeplearning.net/software/theano/tutorial/using_gpu.html

from theano import function, config, shared, tensor
import numpy
import time
vlen = 10 * 30 * 768  # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], tensor.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
    r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, tensor.Elemwise) and
              ('Gpu' not in type(x.op).__name__)
              for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')

执行代码:

THEANO_FLAGS=device=cuda0 python gpu_tutorial1.py

结果报错:
ImportError : No module named pygpu

**

解决方法:(另外除了下面方法可以执行anaconda安装:conda install pygpu)
ps:我这里环境没有使用anaconda,所以尝试用源码安装
前提:以下的环境你安装好了

cmake >= 3.0 (cmake).
python
Cython >= 0.25

如果需要安装cmake请移步:
https://blog.csdn.net/l1028386804/article/details/50779092
** 解决步骤
1:下载源码
git clone https://github.com/Theano/libgpuarray.git
2:进入libgpuarray目录

cd
mkdir Build
cd Build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
make install
cd ..

安装 pygpu:

# This must be done after libgpuarray is installed as per instructions above.
>python setup.py build
>python setup.py install

3:执行链接到系统环境中:

python setup.py build_ext -L MYPREFIX/libI M Y P R E F I X / l i b − I MY_PREFIX/include

注意这里的My_PREFIX是你安装的libgpuarray库目录。默认是在/usr/local下

sudo ldconfig
4:最后我按照官网测试例子:(test device是你环境下的gpu名称)
DEVICE=”” python -c “import pygpu;pygpu.test()”
发现还是不行,找不到libgpuarray
解决办法:
4.1:编辑环境变量文件
vim ~/.bashrc
4.2:添加内容如下:
export LIBGPUARRAY_PATH=/usr/local
export PATH= LIBGPUARRAYPATH/lib: L I B G P U A R R A Y P A T H / l i b : PATH
4.3:生效:
source ~/.bashrc

参考官网信息
http://deeplearning.net/software/libgpuarray/installation.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值