问题
I want to run Tensorflow GPU in Pycharm on Linux Mint.
I tried some guides like these
https://medium.com/@p.venkata.kishore/install-anaconda-tenserflow-gpu-keras-and-pycharm-on-windows-10-6bfb39630e4e
https://medium.com/@kekayan/step-by-step-guide-to-install-tensorflow-gpu-on-ubuntu-18-04-lts-6feceb0df5c0
I run this code
import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
I have got this error
Traceback (most recent call last):
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/alex/PycharmProjects/TfTestGPU/test.py", line 1, in <module>
import tensorflow as tf
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/home/alex/anaconda3/envs/TfTestGPU/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
Process finished with exit code 1
回答1:
First Make sure CUDA and CuDNN has been installed successfully and Configuration should be verified.
CUDA driver version should be sufficient for CUDA runtime version.
Once done, Open PyCharm
Goto File->Settings-> Project Interpreter
Select the appropriate Environment which has tensorflow-gpu installed
Select Run->Edit Configuration->Environment Variables
Since the code is searching for libcublas.so.10.0 ,
Assume like path you find "libcublas.so.10.0" is something like "/home/Alex/anaconda3/pkgs/cudatoolkit-10.0.130-0/lib/"
Add the lib path as LD_LIBRARY_PATH in environment variables as
Name : LD_LIBRARY_PATH
Value : /home/Alex/anaconda3/pkgs/cudatoolkit-10.0.130-0/lib/
Save it and then try to import tensorflow
回答2:
It's kind of confusing in your installment, Do you install the tensorflow in your pycharm or anaconda, because you use pycharm, but there are some error about the anaconda.
- Check the environment variable configuration, both for Linux and pycharm. Be careful the cuda-x in the path. x is the version cuda such as 10.0
- Check the versions of the tensorflow, cuda, cudnn, according to this site.
- Make sure you can find the libcublas.so.10.0 in this folder
/usr/local/cuda-10.0/lib64
. If not, you should reinstall the cudnn. - Sometimes I encounter this problem, but after restarting the computer, it works.
来源:https://stackoverflow.com/questions/55549257/how-to-run-tensorflow-gpu-in-pycharm