图书馆不加载:@rpath / libcudart.7.5。dylib在Mac上的张流量错误

时间:2021-08-13 03:49:15

I'm using OS X El Capitan (10.11.4).

我用的是OS X El Capitan(10.11.4)。

I just downloaded TensorFlow using the pip install instructions here.

我刚刚下载了使用pip安装说明这里的TensorFlow。

Everything went pretty smoothly, though I did get a few warning messages like:

一切都很顺利,尽管我收到了一些警告信息,比如:

The directory '/Users/myusername/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.

目录“/Users/myusername/Library/ cache /pip/http”或其父目录不属于当前用户,缓存已被禁用。请检查该目录的权限和所有者。如果使用sudo执行pip,您可能需要-H标志。

and

You are using pip version 6.0.8, however version 8.1.2 is available. Even though I just installed pip.

您正在使用pip版本6.0.8,但是版本8.1.2是可用的。尽管我刚刚安装了pip。

Then, when I tested TensorFlow in Python, I got the error:

然后,当我在Python中测试TensorFlow时,我得到了错误:

>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/__init__.py", line 48, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: @rpath/libcudart.7.5.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/_pywrap_tensorflow.so
  Reason: image not found

Now, when I try to do pip uninstall tensorflow-0.10.0rc0 it tells me that it's not installed.

现在,当我尝试执行pip卸载tensorflow-0.10.0rc0时,它告诉我它没有安装。

The closest thing I've found to resembling this problem is this issue in the TensorFlow GitHub docs (which I have not tried).

我发现最接近这个问题的是在TensorFlow GitHub文档中出现的这个问题(我还没有尝试过)。

How can I uninstall whatever it did install and get TensorFlow up and running correctly?

如何卸载它所安装的内容,并使TensorFlow正常运行?

3 个解决方案

#1


35  

This error message is displayed if you install the GPU-enabled Mac OS version of TensorFlow (available from release 0.10 onwards) on a machine that does not have CUDA installed.

如果在没有安装CUDA的机器上安装支持gpu的Mac OS版本的TensorFlow(从版本0.10开始就可以使用),将显示此错误消息。

To fix the error, install the CPU version for Python 2.7 or 3.x, as follows:

要修复错误,请为Python 2.7或3安装CPU版本。x,如下:

# Mac OS X, CPU only, Python 2.7:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py2-none-any.whl
$ sudo pip install --upgrade $TF_BINARY_URL

# Mac OS X, CPU only, Python 3.4 or 3.5:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl
$ sudo pip3 install --upgrade $TF_BINARY_URL

See tensorflow versions: https://www.tensorflow.org/versions/

看到tensorflow版本:https://www.tensorflow.org/versions/

#2


3  

To add to @mrry's answer, if you already have CUDA installed but you still get the error, it could be because the CUDA libraries are not on your path. Add the following to your ~/.bashrc or ~/.zshrc:

要添加@mrry的答案,如果您已经安装了CUDA,但仍然得到错误,可能是因为CUDA库不在您的路径上。将以下内容添加到您的~/中。bashrc或(~ / . zshrc:

# export CUDA_HOME=/Developer/NVIDIA/CUDA-7.5 ## This is the default location on macOS
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$CUDA_HOME/lib:$DYLD_LIBRARY_PATH"
export PATH="$CUDA_HOME/bin:$PATH"

Uncomment either of the CUDA_HOMEs or edit it so that it contains your CUDA install. If you do not know where it is installed, try:

取消对CUDA_HOMEs的注释或编辑它,使它包含您的CUDA安装。如果您不知道它安装在哪里,请尝试:

find / -name "*libcudart*"

#3


1  

Certainly installing CUDA is essential, as is ensuring that all the paths are correct. I'm running:

当然,安装CUDA是必不可少的,确保所有路径都是正确的。我运行:

  • TensorFlow 0.12r0
  • 0.12 TensorFlow r0
  • OSX 10.12.1
  • OSX 10.12.1
  • python 2.7 from brew
  • python 2.7从酿造
  • virtualenv to separate my python environments
  • virtualenv分隔我的python环境。
  • CUDA 8.0.55
  • CUDA 8.0.55
  • cudnn-8.0-osx-x64-v5.1
  • cudnn - 8.0 - osx x64 v5.1

On my system I have also had further issues where it appears that the problem originates from the dynamic libraries internally referencing relative paths.

在我的系统中,我还遇到了其他问题,问题似乎源自于内部引用相对路径的动态库。

To discover the @rpath being referenced from _pywrap_tensorflow.so the following code is run:

查找从_pywrap_tensorflow引用的@rpath。因此,运行以下代码:

otool -l /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so

which returned, amongst other things, the following:

其中包括以下内容:

Load command 15
      cmd LC_RPATH
      cmdsize 128
      path $ORIGIN/../../_solib_darwin/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Slib (offset 12)
Load command 16
      cmd LC_RPATH
      cmdsize 48
      path ../local_config_cuda/cuda/lib (offset 12)
Load command 17
      cmd LC_RPATH
      cmdsize 56
      path ../local_config_cuda/cuda/extras/CUPTI/lib (offset 12)

It can be seen that the dynamic library is attempting to find the CUDA libraries within my virtual environment where I installed TensorFlow with pip. It's not looking within my systems environment paths.

可以看到,动态库试图在我的虚拟环境中查找CUDA库,我在其中安装了pip的TensorFlow。它没有在我的系统环境路径中查找。

A hack around of a solution is to dynamically link the CUDA libraries from their /usr/local/cuda/lib location into the site-packages where pip installed TensorFlow inside my virtual environment.

解决方案的一个技巧是将CUDA库从它们的/usr/local/cuda/lib位置动态地链接到站点包中,pip在我的虚拟环境中安装了TensorFlow。

mkdir /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/local_config_cuda

cd /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/local_config_cuda

ln -s /usr/local/cuda .

Will need to re-link when pip upgrades TensorFlow from within the virtual environment.

当pip从虚拟环境中升级TensorFlow时,需要重新链接。

I think this all goes back to the original compilation of TensorFlow that is done for the pip install and I have no idea how to submit a fix, or even if I am correct. Perhaps the original compilation of Tensorflow needs to be more dynamic and not static.

我认为这一切都要追溯到对pip安装所做的TensorFlow的原始编译,我不知道如何提交修复,即使我是正确的。也许最初的Tensorflow编译需要更动态,而不是静态的。

Best of luck!

最好的运气!

#1


35  

This error message is displayed if you install the GPU-enabled Mac OS version of TensorFlow (available from release 0.10 onwards) on a machine that does not have CUDA installed.

如果在没有安装CUDA的机器上安装支持gpu的Mac OS版本的TensorFlow(从版本0.10开始就可以使用),将显示此错误消息。

To fix the error, install the CPU version for Python 2.7 or 3.x, as follows:

要修复错误,请为Python 2.7或3安装CPU版本。x,如下:

# Mac OS X, CPU only, Python 2.7:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py2-none-any.whl
$ sudo pip install --upgrade $TF_BINARY_URL

# Mac OS X, CPU only, Python 3.4 or 3.5:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl
$ sudo pip3 install --upgrade $TF_BINARY_URL

See tensorflow versions: https://www.tensorflow.org/versions/

看到tensorflow版本:https://www.tensorflow.org/versions/

#2


3  

To add to @mrry's answer, if you already have CUDA installed but you still get the error, it could be because the CUDA libraries are not on your path. Add the following to your ~/.bashrc or ~/.zshrc:

要添加@mrry的答案,如果您已经安装了CUDA,但仍然得到错误,可能是因为CUDA库不在您的路径上。将以下内容添加到您的~/中。bashrc或(~ / . zshrc:

# export CUDA_HOME=/Developer/NVIDIA/CUDA-7.5 ## This is the default location on macOS
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$CUDA_HOME/lib:$DYLD_LIBRARY_PATH"
export PATH="$CUDA_HOME/bin:$PATH"

Uncomment either of the CUDA_HOMEs or edit it so that it contains your CUDA install. If you do not know where it is installed, try:

取消对CUDA_HOMEs的注释或编辑它,使它包含您的CUDA安装。如果您不知道它安装在哪里,请尝试:

find / -name "*libcudart*"

#3


1  

Certainly installing CUDA is essential, as is ensuring that all the paths are correct. I'm running:

当然,安装CUDA是必不可少的,确保所有路径都是正确的。我运行:

  • TensorFlow 0.12r0
  • 0.12 TensorFlow r0
  • OSX 10.12.1
  • OSX 10.12.1
  • python 2.7 from brew
  • python 2.7从酿造
  • virtualenv to separate my python environments
  • virtualenv分隔我的python环境。
  • CUDA 8.0.55
  • CUDA 8.0.55
  • cudnn-8.0-osx-x64-v5.1
  • cudnn - 8.0 - osx x64 v5.1

On my system I have also had further issues where it appears that the problem originates from the dynamic libraries internally referencing relative paths.

在我的系统中,我还遇到了其他问题,问题似乎源自于内部引用相对路径的动态库。

To discover the @rpath being referenced from _pywrap_tensorflow.so the following code is run:

查找从_pywrap_tensorflow引用的@rpath。因此,运行以下代码:

otool -l /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so

which returned, amongst other things, the following:

其中包括以下内容:

Load command 15
      cmd LC_RPATH
      cmdsize 128
      path $ORIGIN/../../_solib_darwin/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Slib (offset 12)
Load command 16
      cmd LC_RPATH
      cmdsize 48
      path ../local_config_cuda/cuda/lib (offset 12)
Load command 17
      cmd LC_RPATH
      cmdsize 56
      path ../local_config_cuda/cuda/extras/CUPTI/lib (offset 12)

It can be seen that the dynamic library is attempting to find the CUDA libraries within my virtual environment where I installed TensorFlow with pip. It's not looking within my systems environment paths.

可以看到,动态库试图在我的虚拟环境中查找CUDA库,我在其中安装了pip的TensorFlow。它没有在我的系统环境路径中查找。

A hack around of a solution is to dynamically link the CUDA libraries from their /usr/local/cuda/lib location into the site-packages where pip installed TensorFlow inside my virtual environment.

解决方案的一个技巧是将CUDA库从它们的/usr/local/cuda/lib位置动态地链接到站点包中,pip在我的虚拟环境中安装了TensorFlow。

mkdir /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/local_config_cuda

cd /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/local_config_cuda

ln -s /usr/local/cuda .

Will need to re-link when pip upgrades TensorFlow from within the virtual environment.

当pip从虚拟环境中升级TensorFlow时,需要重新链接。

I think this all goes back to the original compilation of TensorFlow that is done for the pip install and I have no idea how to submit a fix, or even if I am correct. Perhaps the original compilation of Tensorflow needs to be more dynamic and not static.

我认为这一切都要追溯到对pip安装所做的TensorFlow的原始编译,我不知道如何提交修复,即使我是正确的。也许最初的Tensorflow编译需要更动态,而不是静态的。

Best of luck!

最好的运气!