anacondacudavirtualenvconda

how to set the cuda path in the conda environment?


I am using ubuntu 22 LTS. I want to use a different version of Cuda in the conda virtual environment. I want to use a virtual conda environment for tensorflow 1.x and another conda env for tensorflow 2.x and one environment for PyTorch. I add the version of Cuda when I created the environment. My problem is that instead of using the Cuda that is installed in the conda env (ie. conda create -n tf1 cudnn=7.6.5 cudatoolkit=10.1.243), it uses the system cuda. when I type the

nvcc --version

the output is:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_May__3_18:49:52_PDT_2022
Cuda compilation tools, release 11.7, V11.7.64
Build cuda_11.7.r11.7/compiler.31294372_0

how can I set the path to use the specific Cuda version installed in the environment and not the system?


Solution

  • You can set the CUDA_HOME environment variable with this command.

    conda env config vars set CUDA_HOME=""
    

    You should be able to use this command to find the path of your conda-installed CUDA library.

    sudo find / -name nvcc
    

    You might also want to look at this documentation to have environment variables set as part of the activation step.

    https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#saving-environment-variables