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


Posted in Python onSeptember 17, 2020

问题描述:我通过控制台使用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

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

解决办法:

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的问题

在运行就可以了

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

Python 相关文章推荐
解密Python中的描述符(descriptor)
Jun 03 Python
python excel使用xlutils类库实现追加写功能的方法
May 02 Python
Python实现的拟合二元一次函数功能示例【基于scipy模块】
May 15 Python
python实现反转部分单向链表
Sep 27 Python
pycharm 配置远程解释器的方法
Oct 28 Python
Python实现的旋转数组功能算法示例
Feb 23 Python
Python识别快递条形码及Tesseract-OCR使用详解
Jul 15 Python
在主流系统之上安装Pygame的方法
May 20 Python
Python定时任务APScheduler安装及使用解析
Aug 07 Python
Pandas加速代码之避免使用for循环
May 30 Python
Jupyter Notebook内使用argparse报错的解决方案
Jun 03 Python
Anaconda安装pytorch及配置PyCharm 2021环境
Jun 04 Python
Django mysqlclient安装和使用详解
Sep 17 #Python
Pycharm2020最新激活码|永久激活(附最新激活码和插件的详细教程)
Sep 29 #Python
Django返回HTML文件的实现方法
Sep 17 #Python
Pycharm新手使用教程(图文详解)
Sep 17 #Python
Django修改app名称和数据表迁移方案实现
Sep 17 #Python
Python request中文乱码问题解决方案
Sep 17 #Python
python如何使用腾讯云发送短信
Sep 17 #Python
You might like
php命令行使用方法和命令行参数说明
2014/04/08 PHP
php实例分享之二维数组排序
2014/05/15 PHP
PHP如何获取当前主机、域名、网址、路径、端口等参数
2017/06/09 PHP
PHP封装的PDO数据库操作类实例
2017/06/21 PHP
一段实时更新的时间代码
2006/07/07 Javascript
jQuery源码分析-01总体架构分析
2011/11/14 Javascript
js使下拉列表框可编辑不止是选择
2013/12/12 Javascript
js定时调用方法成功后并停止调用示例
2014/04/08 Javascript
jQuery的ready方法详解
2014/11/27 Javascript
jQuery中hover方法和toggle方法使用指南
2015/02/27 Javascript
简述AngularJS相关的一些编程思想
2015/06/23 Javascript
javascript实现checkbox复选框实例代码
2016/01/10 Javascript
Node.js中常规的文件操作总结
2016/10/13 Javascript
原生JS获取元素集合的子元素宽度实例
2016/12/14 Javascript
前端开发之CSS原理详解
2017/03/11 Javascript
JavaScript创建对象_动力节点Java学院整理
2017/06/27 Javascript
详解NodeJs开发微信公众号
2018/05/25 NodeJs
vue使用rem实现 移动端屏幕适配
2018/09/26 Javascript
ES6学习笔记之字符串、数组、对象、函数新增知识点实例分析
2020/01/22 Javascript
基于JavaScript实现大文件上传后端代码实例
2020/08/18 Javascript
[54:05]DOTA2-DPC中国联赛定级赛 SAG vs iG BO3第一场 1月9日
2021/03/11 DOTA
深入浅析Python中list的复制及深拷贝与浅拷贝
2018/09/03 Python
python关于变量名的基础知识点
2020/03/03 Python
css3实现背景图片拉伸效果像桌面壁纸一样
2013/08/19 HTML / CSS
台湾SHOPRO购物行家:亚洲首创影视.3C.家电.优质购物平台
2018/05/07 全球购物
法国票务网站:Ticketmaster法国
2018/07/09 全球购物
美国户外运动商店:Sun & Ski
2018/08/23 全球购物
英国领先的游戏零售商:GAME
2019/09/24 全球购物
爱尔兰橄榄球店:Irish Rugby Store
2019/12/05 全球购物
介绍一下Prototype的$()函数,$F()函数,$A()函数都是什么作用?
2014/03/05 面试题
大学自我评价
2014/02/12 职场文书
社会实践活动总结范文
2014/07/03 职场文书
教师个人总结范文
2015/02/11 职场文书
2019年销售人员的职业生涯规划书
2019/03/25 职场文书
MySQL 不等于的三种使用及区别
2021/06/03 MySQL
Win11局域网共享权限在哪里设置? Win11高级共享的设置技巧
2022/04/05 数码科技