Tensorflow GPU setup: error with CUDA on PyCharm

2020-06-25 04:38发布

I have TF 0.8 installed on Python3, MacOSX El Capitan.

When running a simple test code for TF I get this message:

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:

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
  • in /usr/local/cuda/lib I have an alias called libcudart.7.5.dylib

I have tried several permutations of .bash_profile without success. 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.

6条回答
迷人小祖宗
2楼-- · 2020-06-25 05:06

Could you try TF 0.9, which adds the MacOX GPU support?

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

查看更多
趁早两清
3楼-- · 2020-06-25 05:11

If you're getting this error, make sure you installed CUDA, cuDNN correctly as described in the Tensorflow install instructions. Note the TF, CUDA, cuDNN version you're installing and what Python version you're using.

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:

  • is this happening in PyCharm?
  • is this happening in iPython within PyCharm?
  • is it happening in both?
  • is this happening in iPython in Terminal?

In my case it was happening only in PyCharm. In iPython outside of PyCharm (that is using the Mac 'Terminal' software) everything worked fine. But when doing iPython in PyCharm, or when running the test file through PyCharm, I would get the error. This means it has something to do with PyCharm, not the Tensorflow install.

Make sure your DYLD_LIBRARY_PATH is correctly pointing to the libcudart.7.5.dylib file. Navigate there with Finder, do a Spotlight search search and find the file or its alias. Then place that path in your .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. Go to the upper right corner of the GUI and click the gray down arrow.

enter image description here

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.

enter image description here

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). Note that you need to save this config or else when you close PyCharm it won't stick.

enter image description here

查看更多
ゆ 、 Hurt°
4楼-- · 2020-06-25 05:15

In my case, tensorflow version is 1.1, the dlopen error happens in both

ipython and pycharm

Environment: Cuda version:8.0.62

cudnn version:6

error is a little different in pycharm and 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:

  1. Download cudnn version 5, from

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

  1. Unzip the cudnn. Copy lib/ to /usr/local/cuda/lib. Copy include/ to /usr/local/cuda/include

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

  2. Add the lib directory path to your DYLD_LIBRARY_PATH. like this in my ~/.bash_profile:

    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

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

Requirements to run TensorFlow with GPU support.

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:

...
The NVIDIA drivers associated with CUDA Toolkit 8.0.
cuDNN v5.1. For details, see NVIDIA's documentation.
...

查看更多
闹够了就滚
5楼-- · 2020-06-25 05:24

It appears that you are not finding CUDA on your system. 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.

Please take a look at my answer here.

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

查看更多
家丑人穷心不美
6楼-- · 2020-06-25 05:24

I think the problem is in the SIP (System Integrity Protection). 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

查看更多
Viruses.
7楼-- · 2020-06-25 05:27

As an extension to pepe answer, which is the correct one, I don't mind if the following is integrated to the original answer.

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.

enter image description here

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)

查看更多
登录 后发表回答