【问题标题】:How to install cudnn and cuda toolkit in a python virtual environment?如何在 python 虚拟环境中安装 cudnn 和 cuda 工具包?
【发布时间】:2022-10-15 18:10:50
【问题描述】:

我在当前工作目录中创建了一个 python 虚拟环境。它安装了 cuda-python 以及 tensorflow 和其他软件包。我试图运行 以下脚本检查 tensorflow 是否可以访问 GPU。

python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

该脚本在运行时引发以下错误 -

could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory

根据我在网上看到的,这个错误是由于没有安装 cudnn 和 cudatoolkit 模块造成的。解决方案是使用 anaconda 安装它们,如下所示。

conda install -c anaconda cudnn

上面的命令似乎是在安装安装了 anaconda 的包,但我没有对该目录的写权限。我确实对设置虚拟环境的当前工作目录具有写权限。

现在,有没有办法将 cudnn 和 cuda 工具包安装到当前工作目录中的虚拟环境中? 我基本上想做的是:

source .environment/bin/activate; pip install cudnn;

【问题讨论】:

    标签: python tensorflow pip cudnn


    【解决方案1】:

    请确保您在虚拟环境中,同时按照tested build configuration 安装 CUDA 和 cuDNN 以获得 GPU 支持。

    为此打开 Anaconda 提示符,键入

    conda activate <virtual_environment_name>
    
    conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0  # for tensorflow version >2.5
    

    并使用以下方法安装张量流:

    conda install pip
    pip install tensorflow-gpu  # pip install tensorflow-gpu==<specify version>
    Or
    pip install --upgrade pip
    pip install tensorflow-gpu
    

    现在,验证 GPU 设置:

    python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
    

    请参阅this 链接了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 2019-01-20
      • 1970-01-01
      • 2016-11-11
      • 2017-10-25
      相关资源
      最近更新 更多