0

I use the conda comment to install tensorflow:

conda create -n tf2.6 python=3.9
conda install tensorflow-gpu=2.6

The log tells me it was succesuflly installed.Then in python when I import tensorflow, it shows Could not load dynamic library 'libcudart.so.11.0'. From the log, I found it installed cudatoolkit and cudnn when installing tensorflow. In the directory ./tf2.6/lib, there exist libcudart.so and libcudart.so.11.0. why python cannot recognize it? Some one can give some suggestions. Thank you very much.

In my conda env, there was another version tf2.5. It can work perfectly but I forgot how to installed it since it is a long time when I installed it.

wangwei
  • 45
  • 1
  • 1
  • 7
  • 1
    I don't know why but sometimes conda misses installing cudatoolkit and cudnn, make sure those are in there with conda list (and also that they are the appropriate versions). Also, make sure your python version is supported, usually the cudatools lag a bit behind. – Andrew Holmgren Nov 10 '21 at 17:06

2 Answers2

12

I have the exact same problem, I have found a temporary solution as of now,

doing export LD_LIBRARY_PATH="$CONDA_PREFIX/lib" after activation will include libcudart.so.11.0

If you want to automate it,

add this to env-prefix/etc/conda/activate.d/env_vars.sh

#!/bin/sh

export LD_LIBRARY_PATH="$CONDA_PREFIX/lib"

This will run the script on conda activate and set LD_LIBRARY_PATH

Shriraj Hegde
  • 829
  • 5
  • 18
  • 3
    Thank you. After search from the internet, I found a improved method that can reset the LD_LIBRARY_PATH in the deactivate stage. In the activate.d/env_vars.sh: `export OLD_LD_LIBRARY_PATH=${LD_LIBRARY_PATH} export LD_LIBRARY_PATH=/your/path:${LD_LIBRARY_PATH}` and then in deactivate.d/env_vars.sh: `export LD_LIBRARY_PATH=${OLD_LD_LIBRARY_PATH} unset OLD_LD_LIBRARY_PATH` – wangwei Nov 13 '21 at 08:51
  • 3
    see the link https://stackoverflow.com/questions/46826497/conda-set-ld-library-path-for-env-only – wangwei Nov 13 '21 at 08:54
0

Originally solution what I found:

conda env config vars set LD_LIBRARY_PATH=$CONDA_PREFIX/lib

Source:https://github.com/tensorflow/tensorflow/issues/52988