解决方案:解决用Pycharm连接Ubuntu服务器时环境变量不同步的问题
很多人都知道pycharm可以连接服务器,也可以直接运行服务器的程序。前几天我用pycharm训练网络时,系统提示‘Could not load dynamic library ‘libcudart.so.10.0’’,也就是CUDA库文件打开失败导致GPU不可用。
2020-11-29 10:19:41.562913: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory
2020-11-29 10:19:41.562945: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory
2020-11-29 10:19:41.562975: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory
2020-11-29 10:19:41.563004: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory
2020-11-29 10:19:41.563032: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory
2020-11-29 10:19:41.563062: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory
2020-11-29 10:19:41.468189: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
上网一查,要在.bashrc文件里添加几条导入CUDA路径的指令,我就更迷惑了:我明明之前已经添加了,也在putty的终端上用source命令激活了bashrc文件。之前在终端测试GPU也是可用的。
于是再次在终端测试GPU是否可用
>>>import tensorflow as tf
>>>tf.test.is_gpu_available()
显示CUDA库可以正常打开,GPU也可以正常使用,也就是说在putty上CUDA库的路径已经加入环境变量了
那现在问题就很明显了:pycharm的路径和putty终端上的环境变量不同步。
我恍然大悟:pycharm和putty的连接对于服务器来说是两个完全独立的连接,我如果要在pycharm上导入CUDA的路径,需要单独在pycharm里设置
在pycharm中添加路径参考博客https://blog.csdn.net/DL_ChenBo/article/details/53262230
添加之后在pycharm中可以成功导入CUDA,使用GPU