首页 > 解决方案 > 当我尝试从 pycuda 运行模块时,出现错误:“没有名为 'pycuda._driver' 的模块”

问题描述

我想运行我从这个网站上下来的代码 - https://documen.tician.de/pycuda/tutorial.html - 这是下面的内容。

import pycuda.gpuarray as gpuarray
import pycuda.driver as cuda
import pycuda.autoinit
import numpy

a_gpu = gpuarray.to_gpu(numpy.random.randn(4,4).astype(numpy.float32))
a_doubled = (2*a_gpu).get()
print(a_doubled)
print(a_gpu)

基本上,对于“import pycuda.driver as cuda”这一行,我收到错误消息:

文件“C:\Users\David\Anaconda3\lib\site-packages\pycuda\driver.py”,第 5 行,从 pycuda._driver import * # noqa

ModuleNotFoundError:没有名为“pycuda._driver”的模块

这是有道理的,因为当我查看驱动程序文本文件时,我看到以下几行

try:
    from pycuda._driver import *  # noqa
except ImportError as e:
    if "_v2" in str(e):
        from warnings import warn
        warn("Failed to import the CUDA driver interface, with an error "
                "message indicating that the version of your CUDA header "
                "does not match the version of your CUDA driver.")
    raise

实际上,我的 pycuda 文件夹中没有名为 _driver 的文本文件。那么我该如何解决这个问题呢?当我在终端中编写“pip install pycuda”时,我认为我应该拥有所有文件夹。

标签: pythonpycuda

解决方案


根据您的操作系统,确保您已在正确的 cuda lib 路径上配置了 pycuda。请仔细遵循https://wiki.tiker.net/PyCuda/Installation/Windows 。

但是:看起来您想在 Anaconda 上安装它,因此我建议您改为遵循本指南。https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_PyCUDA_On_Anaconda_For_Windows?lang=en


推荐阅读