wsl下安装cuda各种踩坑记录.assets

news/2025/2/15 15:10:15/
  1. 执行nvcc -V, cuda版本位11.5

请添加图片描述

  1. 删除cuda

    sudo apt-get --purge remove "*cublas*" "*cufft*" "*curand*" \"*cusolver*" "*cusparse*" "*npp*" "*nvjpeg*" "cuda*" "nsight*"
    
  2. 选择对应版本的cuda,下载WSl版本的cuda

请添加图片描述

  1. 执行上部分命令是正常

请添加图片描述

  1. 执行sudo apt-key add /var/cuda-repo-wsl-ubuntu-11-1-local/7fa2af80.pub时,虽然warning了,但是最后还是ok了

    请添加图片描述

  2. 执行sudo apt-get update时会报错

请添加图片描述

  1. 解决,执行如下命令, A4B469963BF863CC根据自己上面出现的NO_PUBKEY填写 GPG error解决方法 - 知乎 (zhihu.com)

     sudo gpg --keyserver keyserver.ubuntu.com --recv A4B469963BF863CCsudo gpg --export --armor A4B469963BF863CC | sudo apt-key add -
    

请添加图片描述

  1. 再次执行sudo apt-get update,虽然都是warning,但好像也成功了

请添加图片描述

  1. 执行sudo apt-get -y install cuda

  2. 安装完成之后,nvcc -V是显示不出cuda版本的,cuda路径在/usr/local/cuda

请添加图片描述

  1. 添加路径

    export PATH=/usr/local/cuda/bin:$PATH
    export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PAT
    

请添加图片描述

再使用su命令切换到root用户下执行添加完路径之后,使用 `source ~/.bashrc` 刷新环境, 运行 `nvcc -V`
  1. 不知道咋回事按照11.1的步骤安装最后是12.1

    请添加图片描述

    删除cuda

    there are two things- nvidia drivers and cuda toolkit- which you may want to remove. If you have installed using apt-get use the following to remove the packages completely from the system:

    To remove cuda toolkit:

    sudo apt-get --purge remove "*cublas*" "cuda*" "nsight*" 
    

    To remove Nvidia drivers:

    sudo apt-get --purge remove "*nvidia*"
    

    If you have installed via source files (assuming the default location to be /usr/local) then remove it using:

    sudo rm -rf /usr/local/cuda*
    

    From cuda 11.4 onwards, an uninstaller script has been provided. Use it for the uninstallation instead:

    # To uninstall cuda
    sudo /usr/local/cuda-11.4/bin/cuda-uninstaller 
    # To uninstall nvidia
    sudo /usr/bin/nvidia-uninstall
    

    If you get the problem of broken packages, it has happened since you added repo to the apt/sources.lst. Run the following to delete it:

    sudo vim /etc/apt/sources.list
    

    Go to the line containing reference to Nvidia repo and comment it by appending # in front of the line, for e.g.:

    #deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /
    

    Then run

    sudo apt-get update 
    

    This will fix the problem.

    References: Nvidia uninstallation

  2. 再尝试使用runfile安装, 执行sudo sh cuda_11.1.0_455.23.05_linux.run,会出现

    请添加图片描述

    查看对应的文件,会有

    请添加图片描述

  3. 加上override参数之后,继续安装

请添加图片描述

  1. 还是11.5版本

    请添加图片描述

  2. 卸载再次重新安装,

    sudo apt-get --purge remove "*cublas*" "cuda*" "nsight*" 
    sudo apt-get --purge remove "*nvidia*"
    sudo rm -rf /usr/local/cuda*
    
  3. 安装过程出现了

    请添加图片描述

    请添加图片描述

  4. 放弃,还是安装runfile版本

  5. 降低gcc版本, 出现错误E: Package ‘g+±7’ has no installation candidate

请添加图片描述

  1. 更换源

    要在vim中清空文本,可以按下ESC键退出编辑模式,然后按两次g键将光标移动到文本的首行,最后按下d和G键,其中d键是小写,G键要切换成大写的,

    # 修改 apt-get 源的配置文件
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份
    sudo vim /etc/apt/sources.list #修改deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
    # deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse#最后执行
    sudo apt-get update
    

    请添加图片描述

  2. 再次安装g++7,降低gcc版本,以便安装cuda

    首先Ubuntu 20.04默认g++9版本太高,会导致CUDA无法安装,因此要先降低g++版本。

    sudo apt-get install gcc-7 g++-7sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 9
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 1sudo update-alternatives --display gccsudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 9
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 1sudo update-alternatives --display g++
    
  3. 降低g++版本之后,可以正常执行 sudo sh cuda_11.1.0_455.23.05_linux.run

    请添加图片描述

  4. 安装完成后显示

    请添加图片描述

  5. 终于正常安装cuda 11.1了,虽然nvidia-smi显示和nvcc -V显示的版本不同,以nvcc -V为主

请添加图片描述

  1. /usr/local目录下也有了 cuda目录

    请添加图片描述

  2. 把之前在root和wu用户中修改的vim ~/.bashrc删除

  3. 更新可执行文件路径,在 vim ~/.bashrc中加入,如果不在 ~/.bashrc中加入的话,下次启动还是找不到cuda

    export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
    
  4. 更新动态链接库路径

    export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    
  5. 安装1.8.1版本的torch https://pytorch.org/get-started/previous-versions/

    # CUDA 11.1
    pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
    
  6. 然后安装torch-geometric, 根据torch和cuda版本选择,

    请添加图片描述

  7. 安装顺序为 torch-scatter2.0.8,torch-sparse0.6.12,torch-cluster1.5.9,torch-spline-conv1.2.1,torch-geometric==1.7.0,我的python版本为3.6, wsl(linux)

  8. 使用nvcc -V命令,发现没有了,原因更改了 /etc/apt/sources.list can’t install nvidia-driver-toolkit on Ubuntu 20.04 LTS - needs uninstallable package - Ask Ubuntu

    方法:在/etc/apt/sources.list中添加

    deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiversedeb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiversedeb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
    

    执行

    sudo apt-cache policy
    sudo apt-get --purge remove "*cublas*" "cuda*" "*nvidia*"
    sudo apt-get clean
    sudo apt-get autoremove
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install nvidia-cuda-toolkit
    

http://www.ppmy.cn/news/42717.html

相关文章

Linux网络编程 第七天

目录 网络编程阶段项目 项目目标 Web服务器开发准备 Html语言基础 Html简介 Html标签介绍 题目标签 文本标签 列表标签 图片标签 超链接标签 http请求消息 请求类型 http响应消息 http常见状态码 http常见文件类型分…

文字描述登入界面到个人界面

登入界面: 创建 src/views/login/index.vue 写入基本框架 然后在 src/router/index.js 中配置登录页的路由表 最后,访问 /login 查看是否能访问到登录页面。 布局结构:导航栏需要用到vant里面的导航栏 、 登入的表单需要用到vant里面的表…

车载之-自定义系统服务

源码梳理 SystemServer的启动,SystemServer是由Zygote启动的。 /*** The main entry point from zygote.*/public static void main(String[] args) {new SystemServer().run();}继续看run()方法,看关键代码,开启服务。 startBootstrapServices主要是针对底层相关的…

Spring-Retry

Spring-Retry 引入Maven依赖 <dependency><groupId>org.springframework.retry</groupId><artifactId>spring-retry</artifactId></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjw…

技术+商业“双轮”驱动,量旋科技加速推进全方位的量子计算解决方案

【中国&#xff0c;深圳】4月14日&#xff0c;在第三个“世界量子日”&#xff0c;以“‘双轮’驱动 加速未来”为主题的量旋科技2023战略发布会在线上举办。 本次发布会&#xff0c;量旋科技全线升级了三大业务线产品&#xff1a;其中重点布局的超导量子计算体系产品&#xf…

优先级队列

目录 前言&#xff1a; 1、PriorityQueue的特性 .2 PriorityQueue常用接口介绍 Ⅰ、PriorityQueue常见的构造方法 Ⅱ、常用的方法 Ⅲ、PriorityQueue的扩容方式&#xff1a; 3、应用 前言&#xff1a; 普通的队列是一种先进先出的数据结构&#xff0c;元素在队列尾追加&…

Ajax简介、axios异步提交

一、Ajax简介 Ajax全称为&#xff1a;“Asynchronous JavaScript and XML”&#xff08;异步JavaScript 和 XML&#xff09; 使用ajax&#xff0c;可以无刷新状态更新页面&#xff0c;并且实现异步提交&#xff0c;提升了用户体验。Ajax其实质是利用浏览器提供的一个特殊的对象…

redis中的持久化操作AOF与RDB区别

通过阅读Redis官网&#xff1a; 持久性&#xff1a;是指将数据写入持久存储&#xff0c;例如固态磁盘 &#xff08;SSD&#xff09; 包括&#xff1a; RDB&#xff08;Redis数据库&#xff09;&#xff1a;RDB持久性按指定的时间间隔执行数据集的时间点快照AOF &#xff08;…