解决Ubuntu18中的pycharm不能调用tensorflow-gpu的问题

 更新时间:2020年09月17日 10:41:47   作者:AnswerThe  
这篇文章主要介绍了解决Ubuntu18中的pycharm不能调用tensorflow-gpu的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

问题描述:我通过控制台使用tensorflow-gpu没问题,但是通过pycharm使用却不可以,如下所示:

通过控制台:

answer@answer-desktop:/$ python
Python 3.7.0 (default, Jun 28 2018, 13:15:42) 
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-02-04 21:37:12.964610: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda-10.1/lib64:/usr/local/cuda-10.1/lib64
2020-02-04 21:37:12.964749: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda-10.1/lib64:/usr/local/cuda-10.1/lib64
2020-02-04 21:37:12.964777: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
>>> print(tf.test.is_gpu_available())
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2020-02-04 21:37:37.267421: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1795795000 Hz
2020-02-04 21:37:37.268461: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55913b67a840 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-02-04 21:37:37.268516: I tensorflow/compiler/xla/service/service.cc:176]  StreamExecutor device (0): Host, Default Version
2020-02-04 21:37:37.272139: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-02-04 21:37:37.481038: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-02-04 21:37:37.481712: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55913b6eb960 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-02-04 21:37:37.481755: I tensorflow/compiler/xla/service/service.cc:176]  StreamExecutor device (0): GeForce GTX 1060 3GB, Compute Capability 6.1
2020-02-04 21:37:37.482022: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-02-04 21:37:37.482528: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties: 
pciBusID: 0000:03:00.0 name: GeForce GTX 1060 3GB computeCapability: 6.1
coreClock: 1.7085GHz coreCount: 9 deviceMemorySize: 5.93GiB deviceMemoryBandwidth: 178.99GiB/s
2020-02-04 21:37:37.482953: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-02-04 21:37:37.485492: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-02-04 21:37:37.487486: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-02-04 21:37:37.487927: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-02-04 21:37:37.490469: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-02-04 21:37:37.491950: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-02-04 21:37:37.499031: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-02-04 21:37:37.499301: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-02-04 21:37:37.500387: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-02-04 21:37:37.500847: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0
2020-02-04 21:37:37.500941: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-02-04 21:37:37.502172: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1096] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-02-04 21:37:37.502212: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102]   0 
2020-02-04 21:37:37.502229: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] 0:  N 
2020-02-04 21:37:37.502436: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-02-04 21:37:37.503003: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-02-04 21:37:37.503593: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1241] Created TensorFlow device (/device:GPU:0 with 2934 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 3GB, pci bus id: 0000:03:00.0, compute capability: 6.1)
True
>>>

返回的True,说明可以

通过pycharm却不行,如下图,返回False

解决办法:

1.修改~/.bashrc

将pycahrm的路径加到环境中,示例如下:

alias pycharm="bash /home/answer/文档/pycharm-professional-2019.3.2/pycharm-2019.3.2/bin/pycharm.sh"

刷新生效:

source ~/.bashrc

2.修改pycharm中的环境变量

选择pycharm 菜单栏Run ——> Run-Edit Configurations ——> Environment variables——> 将cuda的路径加进去 例如:LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64

在运行就可以了

到此这篇关于解决Ubuntu18中的pycharm不能调用tensorflow-gpu的问题的文章就介绍到这了,更多相关pycharm不能调用tensorflow-gpu内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • python解析html开发库pyquery使用方法

    python解析html开发库pyquery使用方法

    PyQuery是一个类似于jQuery的Python库,也可以说是jQuery在Python上的实现,能够以jQuery的语法来操作解析 HTML 文档,易用性和解析速度都很好
    2014-02-02
  • Python游戏推箱子的实现

    Python游戏推箱子的实现

    这篇文章主要介绍了Python游戏推箱子的实现,推箱子游戏是一款可玩性极高的策略解谜手游,游戏中玩家将扮演一名可爱Q萌的角色,下面我们就看看看具体的实现过程吧,需要的小伙伴可以参考一下
    2021-12-12
  • python进阶教程之函数对象(函数也是对象)

    python进阶教程之函数对象(函数也是对象)

    这篇文章主要介绍了python进阶教程之函数对象,函数对象是指函数也是对象,本文还讲解了lambda函数、函数作为参数传递、map()函数、filter()函数、reduce()函数等内容,需要的朋友可以参考下
    2014-08-08
  • python库TextDistance量化文本之间的相似度算法探究

    python库TextDistance量化文本之间的相似度算法探究

    这篇文章主要为大家介绍了python库TextDistance量化文本之间的相似度算法探究,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2024-01-01
  • 如何利用python实现windows的批处理及文件夹操作

    如何利用python实现windows的批处理及文件夹操作

    最近工作中需要几个脚本运行其他程序,几乎像一个Windows批处理文件,这篇文章主要给大家介绍了关于如何利用python实现windows的批处理及文件夹操作的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-01-01
  • python怎么使用xlwt操作excel你知道吗

    python怎么使用xlwt操作excel你知道吗

    这篇文章主要为大家介绍了python使用xlwt操作excel的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助
    2022-01-01
  • python使用mailbox打印电子邮件的方法

    python使用mailbox打印电子邮件的方法

    这篇文章主要介绍了python使用mailbox打印电子邮件的方法,涉及Python打印电子邮件的相关技巧,需要的朋友可以参考下
    2015-04-04
  • pygame实现俄罗斯方块游戏(对战篇1)

    pygame实现俄罗斯方块游戏(对战篇1)

    这篇文章主要为大家详细介绍了pygame实现俄罗斯方块游戏的对战篇,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-10-10
  • 如何处理Python3.4 使用pymssql 乱码问题

    如何处理Python3.4 使用pymssql 乱码问题

    这篇文章主要介绍了如何处理Python3.4 使用pymssql 乱码问题的相关资料,涉及到python pymssql相关知识,对此感兴趣的朋友一起学习吧
    2016-01-01
  • Python Counting Bloom Filter原理与实现详细介绍

    Python Counting Bloom Filter原理与实现详细介绍

    这篇文章主要介绍了Python Counting Bloom Filter原理与实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习吧
    2022-10-10

最新评论