Tensorflow 설치 오류
Python 의 pip 를 이용해서 Tensorflow 를 설치할때에 다음과 같은 오류가 날 수 있다. 2025년 4월 현재 오류가 발생 했다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf 2025-04-28 22:16:15.974938: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-04-28 22:16:20.493515: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\Python3.11\PythonEnv\Lib\site-packages\tensorflow\__init__.py", line 468, in <module> importlib.import_module("keras.src.optimizers") File "D:\Python3.11\Lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\__init__.py", line 2, in <module> from keras.api import DTypePolicy File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\api\__init__.py", line 8, in <module> from keras.api import activations File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\api\activations\__init__.py", line 7, in <module> from keras.src.activations import deserialize File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\__init__.py", line 1, in <module> from keras.src import activations File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\activations\__init__.py", line 33, in <module> from keras.src.saving import object_registration File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\saving\__init__.py", line 7, in <module> from keras.src.saving.saving_api import load_model File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\saving\saving_api.py", line 7, in <module> from keras.src.legacy.saving import legacy_h5_format File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\legacy\saving\legacy_h5_format.py", line 13, in <module> from keras.src.legacy.saving import saving_utils File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\legacy\saving\saving_utils.py", line 10, in <module> from keras.src import models File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\models\__init__.py", line 1, in <module> from keras.src.models.functional import Functional File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\models\functional.py", line 16, in <module> from keras.src.models.model import Model File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\models\model.py", line 12, in <module> from keras.src.trainers import trainer as base_trainer File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\trainers\trainer.py", line 14, in <module> from keras.src.trainers.data_adapters import data_adapter_utils File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\trainers\data_adapters\__init__.py", line 4, in <module> from keras.src.trainers.data_adapters import array_data_adapter File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\trainers\data_adapters\array_data_adapter.py", line 7, in <module> from keras.src.trainers.data_adapters import array_slicing File "D:\Python3.11\PythonEnv\Lib\site-packages\keras\src\trainers\data_adapters\array_slicing.py", line 12, in <module> import pandas File "D:\Python3.11\PythonEnv\Lib\site-packages\pandas\__init__.py", line 22, in <module> from pandas.compat import is_numpy_dev as _is_numpy_dev # pyright: ignore # noqa:F401 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python3.11\PythonEnv\Lib\site-packages\pandas\compat\__init__.py", line 25, in <module> from pandas.compat.numpy import ( File "D:\Python3.11\PythonEnv\Lib\site-packages\pandas\compat\numpy\__init__.py", line 4, in <module> from pandas.util.version import Version File "D:\Python3.11\PythonEnv\Lib\site-packages\pandas\util\__init__.py", line 2, in <module> from pandas.util._decorators import ( # noqa:F401 File "D:\Python3.11\PythonEnv\Lib\site-packages\pandas\util\_decorators.py", line 14, in <module> from pandas._libs.properties import cache_readonly File "D:\Python3.11\PythonEnv\Lib\site-packages\pandas\_libs\__init__.py", line 13, in <module> from pandas._libs.interval import Interval File "pandas\_libs\interval.pyx", line 1, in init pandas._libs.interval ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject |
뭐라뭐라 알수 없는 오류가 나오는데, 해결책이 있다.
numpy 1.x 버전 호환 문제
Tensorflow 는 현재 numpy 2.x 와 잘 호환되지 않는 것으로 보인다. numpy 는 Pandas 를 설치하면서 함게 설치가 되는 것인데, 이때에 2.x 버전이 설치된다. 따라서 numpy 2.x 를 언인스톨하고 numpy 1.x 로 설치해준다.
1 2 |
pip uninstall numpy pip install numpy==1.26.4 # 2025.04 현재 최신 1.x 버전. |
이렇게 하고 나서 Tensorflow 도 언인스톨을 하고 재설치 해준다.
TF_ENABLE_ONEDNN_OPTS=0 문제.
이 문제는 정확하게는 다음과 같다.
I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable
TF_ENABLE_ONEDNN_OPTS=0
.다른 연산 순서로 인해 부동 소수점 반올림 오류가 발생하여 약간 다른 수치 결과가 나타날 수 있습니다.
부동 소수점 반올림 오류 발생 가능성이 있다는 것인데, 이것을 없애기 위해서 환경변수를 설정해야 하라는 것이다. Python 코드로 해결하는 방법은 다음과 같다.
1 2 3 4 |
import os os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' import tensorflow as tf |
Linux 시스템이라면, Bash 쉘을 사용중이라면, 다음과 같이 쉘 환경변수를 지정하면 된다.
1 |
export TF_ENABLE_ONEDNN_OPTS=0; |
Windows 11 시스템이라면 ‘환경변수(Environment Variables)’ -> ‘시스템 변수(Under System Variables)’ 에 TF_ENABLE_ONEDNN_OPTS 이름으로 새로운 변수를 생성하고 값을 0 으로 지정하면 된다.