본문 바로가기

# Python

[Numpy] module 'numpy' has no attribute 'object', 'bool', 'typeDict'. 에러 해결

728x90
반응형

텐서플로를 사용하기 위해서 tensorflow를 import하는 중

import tensorflow as tf

아래와 같은 오류가 나왔다.

 AttributeError: module 'numpy' has no attribute 'object'.
 `np.object` was a deprecated alias for the builtin `object`. To avoid this error in existing code, use `object` by itself. Doing this will not modify any behavior and is safe. 
 The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
     https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

오류에 나와있는 링크인 [numpy 릴리즈노트]에 들어갔다.

위의 내용을 필요한 부분만 요약해보자면

'numpy.int'가 int와 혼란을 야기시키기 때문에 'numpy.int_'로 이름이 변경되었다는 것이다.

즉, tensorflow에서 여전히 numpy.object를 호출하고 있기 때문에 에러가 발생하는 것이다.

Tensorflow에서 위와같은 3가지의 문제가 발생하는데 'object', 'bool', 'typeDict'에서 발생한다.

따라서, 위의 세가지 형태를 현재 사용되는 형태로 변환시키면 해결된다.

해결

위의 문제를 해결하기 위해서는 Tensorflow를 호출하기 전 numpy의 호출 형태를 바로 잡아주면된다.

import numpy as np

np.object = np.object_
np.bool = np.bool_
np.typeDict = np.sctypeDict

위의 코드를 tensorflow를 import하기 전에 호출해주자.

예시)

import numpy as np

np.object = np.object_
np.bool = np.bool_
np.typeDict = np.sctypeDict

from tensorflow.python.client import device_lib
device_lib.list_local_devices()
728x90
반응형

'# Python' 카테고리의 다른 글

[Numpy] Numpy, Pandas, Matplotlib 버전 문제  (2) 2023.11.14
[파이썬 시간 초과]  (0) 2022.06.04