当前位置: 萬仟网 > 科技>操作系统>windows > 解决Ubuntu18中的pycharm不能调用tensorflow-gpu的问题

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

2020年09月18日  | 萬仟网科技  | 我要评论
问题描述:我通过控制台使用tensorflow-gpu没问题,但是通过pycharm使用却不可以,如下所示:通过控制台:answer@answer-desktop:/$ pythonpython 3.

问题描述:我通过控制台使用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内容请搜索萬仟网以前的文章或继续浏览下面的相关文章希望大家以后多多支持萬仟网!

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
Copyright © 2017-2020  萬仟网 保留所有权利. 粤ICP备17035492号-1