Tensorflow安装M1 Mac失败,由于termcolor构建不工作



我试图通过设置一个新的蟒蛇环境并强迫它使用arm64构建在我的M1硅(macOS 12.4)上安装tensorflow:

CONDA_SUBDIR=osx-arm64 conda create -n=NAME python=3.9 -c conda-forge --override-channels

,然后按照开发人员的说明使用M1 GPU:

conda install -c apple tensorflow-deps        
pip3 install tensorflow-macos  

但是我得到了termcolor:

的错误
Building wheel for termcolor (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [34 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/private/var/folders/4n/3tkzf7k15n91rlbqlkh8_3t40000gn/T/pip-install-vihezj4s/termcolor_36abf77c455d4254a5130d8246e91754/setup.py", line 37, in <module>
setup(name='termcolor',
File "/Users/.../opt/anaconda3/envs/c.../lib/python3.9/site-packages/setuptools/_distutils/core.py", line 135, in setup
ok = dist.parse_command_line()
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 484, in parse_command_line
args = self._parse_command_opts(parser, args)
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/site-packages/setuptools/dist.py", line 1104, in _parse_command_opts
nargs = _Distribution._parse_command_opts(self, parser, args)
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 540, in _parse_command_opts
cmd_class = self.get_command_class(command)
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/site-packages/setuptools/dist.py", line 951, in get_command_class
self.cmdclass[command] = cmdclass = ep.load()
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 194, in load
module = import_module(match.group('module'))
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/site-packages/wheel/bdist_wheel.py", line 26, in <module>
from .macosx_libfile import calculate_macosx_platform_tag
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/site-packages/wheel/macosx_libfile.py", line 41, in <module>
import ctypes
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ImportError: dlopen(/Users/nils/opt/anaconda3/envs/care-reconstruction/lib/python3.9/lib-dynload/_ctypes.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libffi.7.dylib
Referenced from: /Users/.../opt/anaconda3/envs/.../lib/python3.9/lib-dynload/_ctypes.cpython-39-darwin.so
Reason: tried: '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/python3.9/lib-dynload/../../libffi.7.dylib' (no such file), '/Users/nils/opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/python3.9/lib-dynload/../../libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../bin/../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../bin/../lib/libffi.7.dylib' (no such file), '/usr/local/lib/libffi.7.dylib' (no such file), '/usr/lib/libffi.7.dylib' (no such file)
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for termcolor
Running setup.py clean for termcolor
Failed to build termcolor

通过添加pip3 install tensorflow-metal完成安装,然后在python3 shell中加载模块tensorflow会产生以下错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/site-packages/tensorflow/__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/Users/.../opt/anaconda3/envs/.../lib/python3.9/site-packages/tensorflow/python/__init__.py", line 24, in <module>
import ctypes
File "/Users/.../opt/anaconda3/envs/care-reconstruction/lib/python3.9/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ImportError: dlopen(/Users/.../opt/anaconda3/envs/.../lib/python3.9/lib-dynload/_ctypes.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libffi.7.dylib
Referenced from: /Users/.../opt/anaconda3/envs/.../lib/python3.9/lib-dynload/_ctypes.cpython-39-darwin.so
Reason: tried: '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/python3.9/lib-dynload/../../libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/python3.9/lib-dynload/.../libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/care-reconstruction/bin/../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../lib/libffi.7.dylib' (no such file), '/Users/.../opt/anaconda3/envs/.../bin/../lib/libffi.7.dylib' (no such file), '/usr/local/lib/libffi.7.dylib' (no such file), '/usr/lib/libffi.7.dylib' (no such file)

运行pip3 uninstall termcolorpip3 install termcolor产生相同的安装错误。

我只是在这里迷路了,现在没有为termcolor构建的功能M1硅吗?还是我哪里搞砸了?

好的。问题出在pip:

conda uninstall termcolor
conda install termcolor

解决了所有问题,tensorflow似乎正在工作(手指交叉!)

请注意,tensorflow-macos目前只能通过pip安装,所以我首先需要让termcolor构建的pip失败,用conda删除它,然后重新安装。

相关内容

  • 没有找到相关文章

最新更新