如何在Pycharm中运行Tensorflow GPU?

问题描述 投票:0回答:2

我想在Linux Mint上运行Pycharm中的Tensorflow GPU。

我试过这些指南

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

我运行这段代码

import tensorflow as tf


sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

我有这个错误

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
python tensorflow pycharm
2个回答
0
投票

你的安装中有点令人困惑,你在pycharm或anaconda中安装张量流,因为你使用pycharm,但是有一些关于anaconda的错误。

  1. 检查Linuxpycharm的环境变量配置。小心路径中的cuda-x。 x是版本cuda,例如10.0
  2. 根据this site,检查tensorflow,cuda,cudnn的版本。
  3. 确保您可以在此文件夹/usr/local/cuda-10.0/lib64中找到libcublas.so.10.0。如果没有,你应该重新安装cudnn。
  4. 有时我遇到这个问题,但重新启动计算机后,它的工作原理。

0
投票

首先确保已成功安装CUDA和CuDNN,并且应验证配置。

CUDA驱动程序版本应该足以用于CUDA运行时版本。

完成后,打开PyCharm

转到文件 - >设置 - >项目解释器

选择安装了tensorflow-gpu的相应环境

选择Run-> Edit Configuration-> Environment Variables

由于代码正在搜索libcublas.so.10.0,

假设你找到“libcublas.so.10.0”之类的路径就像“/home/Alex/anaconda3/pkgs/cudatoolkit-10.0.130-0/lib/”

在环境变量中将lib路径添加为LD_LIBRARY_PATH

名称:LD_LIBRARY_PATH

价值:/home/Alex/anaconda3/pkgs/cudatoolkit-10.0.130-0/lib/

保存它,然后尝试导入tensorflow

© www.soinside.com 2019 - 2024. All rights reserved.