解决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字典写入文件出行首行有空格的问题
Sep 27 Python
Python序列化基础知识(json/pickle)
Oct 19 Python
django反向解析URL和URL命名空间的方法
Jun 05 Python
django rest framework 数据的查找、过滤、排序的示例
Jun 25 Python
Python3+Requests+Excel完整接口自动化测试框架的实现
Oct 11 Python
Python warning警告出现的原因及忽略方法
Jan 31 Python
设置jupyter中DataFrame的显示限制方式
Apr 12 Python
浅谈Python中re.match()和re.search()的使用及区别
Apr 14 Python
详解python 支持向量机(SVM)算法
Sep 18 Python
详解Python小数据池和代码块缓存机制
Apr 07 Python
Python 中的 copy()和deepcopy()
Nov 07 Python
python游戏开发之pygame实现接球小游戏
Apr 22 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 URL验证正则表达式
2011/07/19 PHP
PHP中使用memcache存储session的三种配置方法
2014/04/05 PHP
PHP实现手机号码中间四位用星号(*)隐藏的自定义函数分享
2014/09/27 PHP
thinkphp判断访客为手机端或PC端的方法
2014/11/24 PHP
浅谈ThinkPHP5.0版本和ThinkPHP3.2版本的区别
2017/06/17 PHP
php swoole多进程/多线程用法示例【基于php7nts版】
2019/08/12 PHP
laravel框架中控制器的创建和使用方法分析
2019/11/23 PHP
jQuery ajax 路由和过滤器使用说明
2011/08/02 Javascript
jQuery ui插件的使用方法代码实例
2013/05/08 Javascript
jquery判断RadioButtonList和RadioButton中是否有选中项示例
2013/09/29 Javascript
js获取日期:昨天今天和明天、后天
2014/06/11 Javascript
根据当前时间在jsp页面上显示上午或下午
2014/08/18 Javascript
Jquery $.getJSON 在IE下的缓存问题解决方法
2014/10/10 Javascript
JavaScript数组对象赋值用法实例
2015/08/04 Javascript
使用JS轻松实现ionic调用键盘搜索功能(超实用)
2016/09/06 Javascript
ES6新特性六:promise对象实例详解
2017/04/21 Javascript
JavaScript数据类型和变量_动力节点Java学院整理
2017/06/26 Javascript
详解webpack进阶之插件篇
2017/07/06 Javascript
BootstrapTable加载按钮功能实例代码详解
2017/09/22 Javascript
JS控制鼠标拒绝点击某一按钮的实例
2017/12/29 Javascript
vue实现tab切换外加样式切换方法
2018/03/16 Javascript
微信小程序实现的picker多级联动功能示例
2019/05/23 Javascript
java和js实现的洗牌小程序
2019/09/30 Javascript
Python中使用asyncio 封装文件读写
2016/09/11 Python
Python面向对象类编写细节分析【类,方法,继承,超类,接口等】
2019/01/05 Python
利用jupyter网页版本进行python函数查询方式
2020/04/14 Python
基于plt.title无法显示中文的快速解决
2020/05/16 Python
Python日志器使用方法及原理解析
2020/09/27 Python
Puritan’s Pride(普丽普莱)官方网站:美国最大最全的保健品公司之一
2016/10/23 全球购物
软件配置管理有什么好处
2015/04/15 面试题
高等教育学专业自荐书
2014/06/17 职场文书
2014年销售经理工作总结
2014/12/01 职场文书
2016新年感言
2015/08/03 职场文书
2016学雷锋优秀志愿者事迹材料
2016/02/25 职场文书
Python 内置函数速查表一览
2021/06/02 Python
2007年老电脑安装win11会怎么样? 网友实测win11在老电脑运行良好
2021/11/21 数码科技