Django Girls and Boys 備忘録

Python、Selenium、Django、java、iPhoneアプリ、Excelマクロなどで気付いたこと、覚えておきたいことなどを載せていきます。

【Unity Python】ML-Agentsで”AttributeError: module 'numpy' has no attribute 'float'.”のエラーが表示された時の解決方法


前回はUnityでML-Agentsを使って学習をさせようとした時のエラー

 

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

 

の解決方法として「protobufのバージョンを3.20.xに下げる」という内容の紹介でしたが、一難去ってまた一難で今度はまた次のようなエラーが発生しました。

 

AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
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

 

この解決方法が分かったので備忘録として残しておきまます。

 

 

 

 

 

1.エラー内容

 

先程の内容ですが、

 

AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
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は、 Ver.1.20 で numpy.float や numpy.int などが非推奨(deprecatede)となり、 Ver.1.24で削除したようです。

 

2.解決方法

 

 

これもエラーの原因はnumpyのバージョンが高すぎることだったためバージョンを下げることで解決できます。

 

numpy をVer. 1.24より古いものに入れなおせばいいようなのですが、Ver.1.20以降だとWarningが出ます。

 

なので、以下ではnumpyを一旦アンインストール後Ver.1.19をインストールしています。

 

pip uninstall numpy

 

pip install numpy==1.19

 

以上が”AttributeError: module 'numpy' has no attribute 'float'.”のエラーが表示された時の解決方法になります。