解决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中for语句简单遍历数据的方法
May 07 Python
python中的代码编码格式转换问题
Jun 10 Python
win与linux系统中python requests 安装
Dec 04 Python
python 将列表中的字符串连接成一个长路径的方法
Oct 23 Python
简单了解python高阶函数map/reduce
Jun 28 Python
python通过TimedRotatingFileHandler按时间切割日志
Jul 17 Python
Python统计时间内的并发数代码实例
Dec 28 Python
keras中模型训练class_weight,sample_weight区别说明
May 23 Python
python 瀑布线指标编写实例
Jun 03 Python
Django数据统计功能count()的使用
Nov 30 Python
python实现发送QQ邮件(可加附件)
Dec 23 Python
Python 的演示平台支持 WSGI 接口的应用
Apr 20 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
用windows下编译过的eAccelerator for PHP 5.1.6实现php加速的使用方法
2007/09/30 PHP
PHP输出数组中重名的元素的几种处理方法
2012/09/05 PHP
比较简单的百度网盘文件直链PHP代码
2013/03/24 PHP
win7+apache+php+mysql环境配置操作详解
2013/06/10 PHP
PHP连接Nginx服务器并解析Nginx日志的方法
2015/08/16 PHP
javascript生成/解析dom的CDATA类型的字段的代码
2007/04/22 Javascript
JS自动缩小超出大小的图片
2012/10/12 Javascript
AngularJS控制器继承自另一控制器
2016/05/09 Javascript
解决给dom元素绑定click等事件无效问题的方法
2017/02/17 Javascript
jquery Easyui Datagrid实现批量操作(编辑,删除,添加)
2017/02/20 Javascript
react实现pure render时bind(this)隐患需注意!
2017/03/09 Javascript
JavaScript实现简单的双色球(实例讲解)
2017/07/31 Javascript
seajs模块压缩问题与解决方法实例分析
2017/10/10 Javascript
vue cli构建的项目中请求代理与项目打包问题
2018/02/26 Javascript
vue框架搭建之axios使用教程
2018/07/11 Javascript
AngularJS实现的鼠标拖动画矩形框示例【可兼容IE8】
2019/05/17 Javascript
ionic2.0双击返回键退出应用
2019/09/17 Javascript
JavaScript, select标签元素左右移动功能实现
2020/05/14 Javascript
解决vue的touchStart事件及click事件冲突问题
2020/07/21 Javascript
在Django框架中伪造捕捉到的URLconf值的方法
2015/07/18 Python
Python 内置函数complex详解
2016/10/23 Python
如何用python写一个简单的词法分析器
2018/12/18 Python
python实现多层感知器MLP(基于双月数据集)
2019/01/18 Python
使用python判断jpeg图片的完整性实例
2019/06/10 Python
基于keras输出中间层结果的2种实现方式
2020/01/24 Python
python里的单引号和双引号的有什么作用
2020/06/17 Python
python的launcher用法知识点总结
2020/08/07 Python
css3媒体查询中device-width和width的区别详解
2020/03/27 HTML / CSS
借助HTML5 Canvas来绘制三角形和矩形等多边形的方法
2016/03/14 HTML / CSS
HTML5 manifest离线缓存的示例代码
2018/08/08 HTML / CSS
毕业生求职的求职信
2013/12/05 职场文书
初中三好学生事迹材料
2014/01/13 职场文书
公司财务人员岗位职责
2015/04/14 职场文书
运动会宣传语
2015/07/13 职场文书
推广普通话宣传标语口号
2015/12/26 职场文书
Python图像处理之图像拼接
2021/04/28 Python