python - 当我尝试从 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”时,我认为我应该拥有所有文件夹。
解决方案
根据您的操作系统,确保您已在正确的 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
推荐阅读
- arcgis-js-api - Web应用程序ArcGIS JS API错误添加图层
- angular - 离子清除数据
- c++ - What is the most efficient way to calling a function every n seconds in c++?
- firebase - Writing Database rules for Firebare cloud storage
- sql-loader - 如何在不将表列数据类型从 nvarchar2(2000) 更改为 nclob 的情况下通过 sqlldr .ctl 加载超过 4000 个字符的字段数据
- docker - 使用远程开发扩展附加到 docker 映像的权限问题
- encoding - MOV指令的x86-64编码,奇怪的情况
- sql - 数据库关系如何在数据库中工作
- ssl - Heroku Godaddy 裸域 SSL HTTPS
- html - 使用 flexbox 将元素引导到底部