解决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内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • win10系统Anaconda和Pycharm的Tensorflow2.0之CPU和GPU版本安装教程

    tf2.0的三个优点: 1.方便搭建网络架构: 2.自动求导 3.GPU加速(便于大数据计算) 安装过程(概要提示) step1:安装annaconda3 step2:安装pycharm step3:安装tensorflow2.0 cpu版本 (1)进入anaconda prompt(anaconda3) (2)默认为(base)环境 (3)输入python,查看python版本:输入exit()退出 (4)输入conda info --envs查看虚拟环境 (5)此处以在(base)环境中安装

  • 解决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 "l

  • 解决Django中调用keras的模型出现的问题

    笔者小白在用Django写一个表格单据图片的识别应用的时候,遇到了调用基于Tensorflow的keras模型出错的问题. 出现的错误信息类似于以下: ValueError: Tensor Tensor("Placeholder:0", shape=(3, 3, 1, 32), dtype=float32) 通过查询相关的资料,对解决的方式做一个记录. 方法1.通过导入 import Keras 然后在构建模型前面加一句 keras.backend.clear_session() 方法

  • 解决pycharm无法调用pip安装的包问题

    问题:pycharm无法调用pip安装的包 原因:pycharm没有设置解析器 解决方法: 打开pycharm->File->Settings->Project Interpreter->设置为你的python路径,我的是:C:\Python27\python.exe,你们根据各自python安装路径修改一下即可 可以先在terminal中,python 显示当前版本,再选择路径,因为通过pip安装的包都在该版本下 有时候需要重新建立一个工程,是因为你的工程混乱了,不知道用哪个py

  • 快速解决fragment中onActivityResult不调用的问题

    fragment 通过startActivityForResult方法启动另一个activity,返回时,不调用onActivityResult方法, 解决步骤: 1.  在Fragment所属的Activity中,重写了onActivityResult方法,确保加上super.onActivityResult @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { sup

  • 解决pandas无法在pycharm中使用plot()方法显示图像的问题

    最近用了pycharm,感觉还不错,就是pandas中Series.DataFrame的plot()方法不显示图片就给我结束了,但是我在ipython里就能画图 以前的代码是这样的 import matplotlib.pyplot as plt from pandas import DataFrame,Series Series([4,5,7]).plot() 找了半天 发现只要加个 plt.show() 就可以显示图像了了 import matplotlib.pyplot as plt fro

  • 解决vue中使用Axios调用接口时出现的ie数据处理问题

    1.问题 近期在使用vue2 + axios 调用接口时碰到一个IE中很奇葩的问题,让我头痛了很久. 废话不多扯,就是在其他浏览器中调用接口返回数据然后可以很顺利的进行处理,但在IE(9-11)中发现发送请求是成功的而且也能抓到服务端返回来的数据.却发现在处理返回来的数据的时候处理的有点问题,怎么搞就是不行. 2.处理过程及方法 我使用了console大法去解决这个问题,具体是这样的:我先将服务器返回过来的数据打印到浏览器控制台,结果发现都能打印出来,这个时候就郁闷了,明明有数据为何在IE上还是

  • 解决在Python编辑器pycharm中程序run正常debug错误的问题

    初学Python,写了一小段程序,在pycharm中debug一直报错,在网上搜了很久,尝试多种方法后还是没有用. 尝试了很久之后,发现这个问题是由于: 1.程序中有中文注释. 2.程序保存路径有中文. 最终我的解决方法是设置pycharm的编码方式.进入file>setting,在输入框搜索encoding 把GBK设置成UTF-8,再重启软件就OK了! 以上这篇解决在Python编辑器pycharm中程序run正常debug错误的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希

  • 解决Springboot中Feignclient调用时版本问题

    目录 大的背景就是 错误如下 这是Springboot版本不一致导致的问题 解决办法如下 现有Springboot项目三个,分别为jpmc-adapter, gsdic-api, twpre-api.gsdic-api, twpre-api是公共的服务,对外提供Restful的API,通过feign client去调用. 大的背景就是 jpmc-adapter现在需要调用另外两个公共的服务. Springboot版本: jpmc-adapter           1.5.9 gsdic-api

  • 解决python中无法自动补全代码的问题

    自已理解自我总结出来的方法,供自己以后使用 #coding:utf-8 from cv2 import * #这里表示让cv2的智能提示功能可用,但是这句话却没有导入cv2模块,不知道什么原因 import tensorflow as tf import tensorflow.contrib as contrib #这句话表示让contrib的代码自动补全功能可用,不知道为啥,比如输入contrib.等一会后面就会自动提示出现很多方法,但是输入tensorflow.contrib.却没有任何反应

  • 解决Keras中循环使用K.ctc_decode内存不释放的问题

    如下一段代码,在多次调用了K.ctc_decode时,会发现程序占用的内存会越来越高,执行速度越来越慢. data = generator(...) model = init_model(...) for i in range(NUM): x, y = next(data) _y = model.predict(x) shape = _y.shape input_length = np.ones(shape[0]) * shape[1] ctc_decode = K.ctc_decode(_y,

随机推荐