简体   繁体   English

Tensorflow GPU设置:PyCharm上的CUDA错误

[英]Tensorflow GPU setup: error with CUDA on PyCharm

I have TF 0.8 installed on Python3, MacOSX El Capitan. 我在Python3,MacOSX El Capitan上安装了TF 0.8。

When running a simple test code for TF I get this message: 运行TF的简单测试代码时,我收到以下消息:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): 
Library not loaded: @rpath/libcudart.7.5.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so
  Reason: image not found

My .bash_profile is as follows: 我的.bash_profile如下:

export PATH=/usr/local/bin:$PATH
export DYLD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-7.5/lib:/usr/local/cuda/lib
  • in /Developer/NVIDIA/CUDA-7.5/lib I have a file called libcudart.7.5.dylib 在/Developer/NVIDIA/CUDA-7.5/lib我有一个名为libcudart.7.5.dylib文件
  • in /usr/local/cuda/lib I have an alias called libcudart.7.5.dylib 在/ usr / local / cuda / lib我有一个名为libcudart.7.5.dylib 的别名

I have tried several permutations of .bash_profile without success. 我已经尝试了几个.bash_profile排列没有成功。 ANy idea what may be wrong? 任何想法可能有什么不对?

Note that I can successfully use my GPU with Theano so there's no reason to believe the GPU/cuDNN/CUDA install may be faulty. 请注意,我可以成功地将我的GPU与Theano一起使用,因此没有理由相信GPU / cuDNN / CUDA安装可能有问题。

If you're getting this error, make sure you installed CUDA, cuDNN correctly as described in the Tensorflow install instructions. 如果您收到此错误,请确保按照Tensorflow安装说明中的说明正确安装了CUDA,cuDNN。 Note the TF, CUDA, cuDNN version you're installing and what Python version you're using. 请注意您正在安装的TF,CUDA,cuDNN版本以及您正在使用的Python版本。

Filenames, paths etc frequently vary, so small tweaks in filenames and paths may be needed in your case if errors are cropping up. 文件名,路径等经常变化,因此如果出现错误,可能需要在文件名和路径中进行小的调整。 Sometimes it's hard for others to help you because your system may have a very specific path setup/version that cannot be understood by someone in a forum. 有时候其他人很难帮助你,因为你的系统可能有一个非常具体的路径设置/版本,论坛中的某个人无法理解。

If you're getting exactly the error I'm describing in the OP, take a step back and check: 如果您收到我在OP中描述的错误,请退后一步并检查:

  • is this happening in PyCharm? 这是在PyCharm发生的吗?
  • is this happening in iPython within PyCharm? 这是在PyCharm内的iPython中发生的吗?
  • is it happening in both? 这两件事都发生了吗?
  • is this happening in iPython in Terminal? 这是在终端的iPython中发生的吗?

In my case it was happening only in PyCharm. 在我的情况是发生在PyCharm。 In iPython outside of PyCharm (that is using the Mac 'Terminal' software) everything worked fine. PyCharm之外的 iPython (即使用Mac'终端'软件)一切正常。 But when doing iPython in PyCharm, or when running the test file through PyCharm, I would get the error. 但是当在PyCharm中进行iPython时,或者通过PyCharm运行测试文件时,我会得到错误。 This means it has something to do with PyCharm, not the Tensorflow install. 这意味着它与PyCharm有关,而不是Tensorflow安装。

Make sure your DYLD_LIBRARY_PATH is correctly pointing to the libcudart.7.5.dylib file. 确保您的DYLD_LIBRARY_PATH正确指向libcudart.7.5.dylib文件。 Navigate there with Finder, do a Spotlight search search and find the file or its alias. 使用Finder导航到该处,执行Spotlight搜索搜索并查找文件或其别名。 Then place that path in your .bash_profile . 然后将该路径放在.bash_profile In my case, this is working: 就我而言,这是有效的:

export DYLD_LIBRARY_PATH=/usr/local/cuda/lib

If your problem is PyCharm, a specific configuration is needed. 如果您的问题是PyCharm,则需要特定配置。 Go to the upper right corner of the GUI and click the gray down arrow. 转到GUI的右上角,然后单击灰色向下箭头。

在此输入图像描述

Choose "Edit Configuration". 选择“编辑配置”。 You will see an Environment option where you need to click on the ... box and enter the DYLD_LIBRARY_PATH that applies to your case. 您将看到一个Environment选项,您需要单击...框并输入适用于您的案例的DYLD_LIBRARY_PATH

在此输入图像描述

Note that there's an Environment option for the specific file you're working on (it will be highlighted in the left panel) and for Defaults (put DYLD_... there as well if you want future files you create to have this). 请注意,您正在处理的特定文件有一个Environment选项(它将在左侧面板中突出显示)和Defaults(如果您希望将来创建的文件也包含DYLD_...也可以使用DYLD_... )。 Note that you need to save this config or else when you close PyCharm it won't stick. 请注意,您需要保存此配置,否则当您关闭PyCharm时它不会粘住。

在此输入图像描述

As an extension to pepe answer, which is the correct one, I don't mind if the following is integrated to the original answer. 作为pepe答案的延伸,这是正确的答案,我不介意将以下内容整合到原始答案中。

I would like to add that if you wish to make this change permanent in pyCharm (affects only the current project) and not having it to do for every net file, is possible, from the interface shown above by pepe, by going under the "Default" to set the DYLD_LIBRARY_PATH. 我想补充一点,如果你想在pyCharm中永久地改变这个(只影响当前的项目)并且没有让它对每个网络文件都做,那么可以从pepe上面显示的界面,通过“默认“设置DYLD_LIBRARY_PATH。

在此输入图像描述

Keep in mind, that this change by itself it doesn't alter the run configuration of the current script, which eventually still need to be manually changed ( or deleted and regenerated from the new defaults) 请记住,这个更改本身并不会改变当前脚本的运行配置,最终仍需要手动更改(或从新默认值中删除和重新生成)

Could you try TF 0.9, which adds the MacOX GPU support? 你能试试TF 0.9,它增加了MacOX GPU的支持吗?

https://github.com/tensorflow/tensorflow/blob/r0.9/RELEASE.md https://github.com/tensorflow/tensorflow/blob/r0.9/RELEASE.md

It appears that you are not finding CUDA on your system. 您似乎没有在系统上找到CUDA。 This could be for a number of reasons including installing CUDA for one version of python while running a different version of python that isn't aware of the other versions installed files. 这可能有很多原因,包括为一个版本的python安装CUDA,同时运行不知道其他版本安装文件的不同版本的python。

Please take a look at my answer here. 请在这里查看我的答案。

https://stackoverflow.com/a/41073045/1831325 https://stackoverflow.com/a/41073045/1831325

In my case, tensorflow version is 1.1, the dlopen error happens in both 在我的例子中,tensorflow版本是1.1,两个都发生了dlopen错误

ipython and pycharm ipython和pycharm

Environment: Cuda version:8.0.62 环境:Cuda版本:8.0.62

cudnn version:6 cudnn版本:6

error is a little different in pycharm and ipython. pycharm和ipython中的错误有点不同。 I cannot remeber too much detail, but ipython says there is no libcudnn.5.dylib , but pycharm just says there is import error, image not found Solution: 我不能记得太多的细节,但是ipython说没有libcudnn.5.dylib ,但是pycharm只是说有导入错误,找不到图像解决方法:

  1. Download cudnn version 5, from 下载cudnn版本5,来自

https://developer.nvidia.com/rdp/cudnn-download https://developer.nvidia.com/rdp/cudnn-download

  1. Unzip the cudnn. 解压缩cudnn。 Copy lib/ to /usr/local/cuda/lib. 将lib /复制到/ usr / local / cuda / lib。 Copy include/ to /usr/local/cuda/include 复制include /到/ usr / local / cuda / include

    unzip cuda.zip unzip cuda.zip
    cd cuda cd cuda
    sudo cp -r lib /usr/local/cuda/lib sudo cp -r lib / usr / local / cuda / lib
    sudo cp include/cudnn.h /usr/local/cuda/include sudo cp include / cudnn.h / usr / local / cuda / include

  2. Add the lib directory path to your DYLD_LIBRARY_PATH. 将lib目录路径添加到DYLD_LIBRARY_PATH。 like this in my ~/.bash_profile: 在我的〜/ .bash_profile中这样:

    export DYLD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-8.0/lib:/usr/local/cuda/lib${DYLD_LIBRARY_PATH:+:${DYLD_LIBRARY_PATH}} export DYLD_LIBRARY_PATH = / Developer / NVIDIA / CUDA-8.0 / lib:/ usr / local / cuda / lib $ {DYLD_LIBRARY_PATH:+:$ {DYLD_LIBRARY_PATH}}

In the tensorflow official installation guide, it says need cudnn 5.1, so ,this is all about careless 在tensorflow官方安装指南中,它说需要cudnn 5.1,所以,这都是粗心的

https://www.tensorflow.org/install/install_mac https://www.tensorflow.org/install/install_mac

Requirements to run TensorFlow with GPU support. 在GPU支持下运行TensorFlow的要求。

If you are installing TensorFlow with GPU support using one of the mechanisms described in this guide, then the following NVIDIA software must be installed on your system: 如果使用本指南中介绍的某种机制安装TensorFlow并支持GPU,则必须在系统上安装以下NVIDIA软件:

... ...
The NVIDIA drivers associated with CUDA Toolkit 8.0. 与CUDA Toolkit 8.0相关的NVIDIA驱动程序。
cuDNN v5.1 . cuDNN v5.1 For details, see NVIDIA's documentation. 有关详细信息,请参阅NVIDIA的文档。
... ...

I think the problem is in the SIP (System Integrity Protection). 我认为问题出在SIP(系统完整性保护)中。 Restricted processes run with cleared environment variables and you got this error. 受限制的进程使用已清除的环境变量运行,并且您收到此错误。

You need to go to Recovery Mode, start Terminal and input 您需要进入恢复模式,启动终端并输入

$ csrutil disable

, and reboot ,并重新启动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM