解决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中的anydbm模版和shelve模版使用指南
Jul 09 Python
Python运行报错UnicodeDecodeError的解决方法
Jun 07 Python
利用python实现xml与数据库读取转换的方法
Jun 17 Python
Python中的上下文管理器和with语句的使用
Apr 17 Python
使用matplotlib中scatter方法画散点图
Mar 19 Python
django 配置阿里云OSS存储media文件的例子
Aug 20 Python
Python3显示当前时间、计算时间差及时间加减法示例代码
Sep 07 Python
centos7中安装python3.6.4的教程
Dec 11 Python
python让函数不返回结果的方法
Jun 22 Python
matplotlib 多个图像共用一个colorbar的实现示例
Sep 10 Python
python判断all函数输出结果是否为true的方法
Dec 03 Python
Python 装饰器(decorator)常用的创建方式及解析
Apr 24 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
基于mysql的论坛(1)
2006/10/09 PHP
PHP常用特殊运算符号和函数总结(php新手入门必看)
2013/02/02 PHP
php制作圆形用户头像的实例_自定义封装类源代码
2017/09/18 PHP
php写入txt乱码的解决方法
2019/09/17 PHP
JS代码判断IE6,IE7,IE8,IE9的函数代码
2013/08/02 Javascript
Javascript排序算法之合并排序(归并排序)的2个例子
2014/04/04 Javascript
JavaScript删除数组元素的方法
2015/03/20 Javascript
jQuery选择器源码解读(三):tokenize方法
2015/03/31 Javascript
JS实现仿微博可关闭弹出层效果
2015/09/21 Javascript
jQuery的内容过滤选择器学习教程
2016/04/18 Javascript
js前端日历控件(悬浮、拖拽、自由变形)
2017/03/02 Javascript
微信小程序商城项目之淘宝分类入口(2)
2017/04/17 Javascript
浅析webpack 如何优雅的使用tree-shaking(摇树优化)
2017/08/16 Javascript
swiper动态改变滑动内容的实现方法
2018/01/17 Javascript
Vue父组件调用子组件事件方法
2018/02/23 Javascript
小程序页面动态配置实现方法
2019/02/05 Javascript
微信小程序点餐系统开发常见问题汇总
2019/08/06 Javascript
微信小程序下拉加载和上拉刷新两种实现方法详解
2019/09/05 Javascript
多种类型jQuery网页验证码插件代码实例
2021/01/09 jQuery
详解Python中的type()方法的使用
2015/05/21 Python
Python基于time模块求程序运行时间的方法
2017/09/18 Python
简单了解Django ContentType内置组件
2019/07/23 Python
pandas将多个dataframe以多个sheet的形式保存到一个excel文件中
2019/10/10 Python
Python发起请求提示UnicodeEncodeError错误代码解决方法
2020/04/21 Python
解决PyCharm无法使用lxml库的问题(图解)
2020/12/22 Python
结合CSS3的布局新特征谈谈常见布局方法
2016/01/22 HTML / CSS
用CSS3的box-reflect设置文字倒影效果的方法讲解
2016/03/07 HTML / CSS
css3 盒模型以及box-sizing属性全面了解
2016/09/20 HTML / CSS
德国汉莎航空中国官网: Lufthansa中国
2017/03/30 全球购物
奢华的意大利皮革手袋:Bene Handbags
2019/10/29 全球购物
大学活动邀请函
2014/01/28 职场文书
公司内部升职自荐信
2015/03/27 职场文书
超市督导岗位职责
2015/04/10 职场文书
win10以太网连接不上怎么办?Win10连接以太网详细教程
2022/04/08 数码科技
Python实现将多张图片合成MP4视频并加入背景音乐
2022/04/28 Python
CSS 实现磨砂玻璃(毛玻璃)效果样式
2023/05/21 HTML / CSS