最新版のtensorflow2.2.0を入れ(pip install)、インポートすると動きません。
In []: import tensorflow as tf ---------------------------------------------------------------------------ImportError Traceback (most recent call last) ~/venv/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py in <module> 57 ---> 58 from tensorflow.python.pywrap_tensorflow_internal import * 59 ~/venv/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py in <module> 27 return _mod ---> 28 _pywrap_tensorflow_internal = swig_import_helper() 29 del swig_import_helper ~/venv/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py in swig_import_helper() 23 try: ---> 24 _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) 25 finally: /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py in load_module(name, file, filename, details) 241 else: --> 242 return load_dynamic(name, filename, file) 243 elif type_ == PKG_DIRECTORY: /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py in load_dynamic(name, path, file) 341 name=name, loader=loader, origin=path) --> 342 return _load(spec) 343 ImportError: dlopen(/Users/名前/venv/lib/python3.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): Symbol not found: _SecKeyCopyExternalRepresentation Referenced from: /Users/名前/venv/lib/python3.7/site-packages/tensorflow/python/../libtensorflow_framework.2.dylib Expected in: /System/Library/Frameworks/Security.framework/Versions/A/Security in /Users/名前/venv/lib/python3.7/site-packages/tensorflow/python/../libtensorflow_framework.2.dylib During handling of the above exception, another exception occurred: ImportError Traceback (most recent call last) <ipython-input-1-d6579f534729> in <module> ----> 1 import tensorflow ~/venv/lib/python3.7/site-packages/tensorflow/__init__.py in <module> 39 import sys as _sys 40 ---> 41 from tensorflow.python.tools import module_util as _module_util 42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader 43 ~/venv/lib/python3.7/site-packages/tensorflow/python/__init__.py in <module> 48 import numpy as np 49 ---> 50 from tensorflow.python import pywrap_tensorflow 51 52 # Protocol buffers ~/venv/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py in <module> 67 for some common reasons and solutions. Include the entire stack trace 68 above this error message when asking for help.""" % traceback.format_exc() ---> 69 raise ImportError(msg) 70 71 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long ImportError: Traceback (most recent call last): File "/Users/名前/venv/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "/Users/名前/venv/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "/Users/名前/venv/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py", line 342, in load_dynamic return _load(spec) ImportError: dlopen(/Users/名前/venv/lib/python3.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): Symbol not found: _SecKeyCopyExternalRepresentation Referenced from: /Users/名前/venv/lib/python3.7/site-packages/tensorflow/python/../libtensorflow_framework.2.dylib Expected in: /System/Library/Frameworks/Security.framework/Versions/A/Security in /Users/名前/venv/lib/python3.7/site-packages/tensorflow/python/../libtensorflow_framework.2.dylib Failed to load the native TensorFlow runtime. See https://www.tensorflow.org/install/errors for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.
恐らくMacのOSが10.11で古いことが関係しているのだと思われます。
そこでhttps://qiita.com/hitokuno/items/f92a7a9f9bb9cd326eb4
を参考にしてTensorFlow v0.11.0 RC1を入れたところ動作しました。しかしkerasを使うとエラーが出てしまいました。
In []: import keras --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) ~/venv/lib/python3.7/site-packages/keras/__init__.py in <module> 2 try: ----> 3 from tensorflow.keras.layers.experimental.preprocessing import RandomRotation 4 except ImportError: ModuleNotFoundError: No module named 'tensorflow.keras' During handling of the above exception, another exception occurred: ImportError Traceback (most recent call last) <ipython-input-2-88d96843a926> in <module> ----> 1 import keras ~/venv/lib/python3.7/site-packages/keras/__init__.py in <module> 4 except ImportError: 5 raise ImportError( ----> 6 'Keras requires TensorFlow 2.2 or higher. ' 7 'Install TensorFlow via `pip install tensorflow`') 8 ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
kerasを使うのが最終目的です。どうすれば解決するでしょうか?
回答2件
あなたの回答
tips
プレビュー