--- lang: ja-jp breaks: true --- # Python `import keras` で、 `AttributeError module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects` とエラーとなる場合の対応。【解決】 2021-07-22 > AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects' > https://qiita.com/hiro716/items/f3a1c9d926d345f514cf > condaとpip:混ぜるな危険 > https://onoz000.hatenablog.com/entry/2018/02/11/142347 以下の部分でエラーとなる。 ```python= import keras ``` ## 環境 ```shell= > python -V Python 3.8.10 ``` ## モジュールを一旦アンインストールして、インストールし直してみる。 ```shell= pip uninstall tensorflow -y pip uninstall tensorflow-gpu -y pip uninstall keras -y conda uninstall tensorflow -y conda uninstall tensorflow-gpu -y conda uninstall keras -y ``` ```shell= pip install tensorflow-gpu pip install keras ``` または、 ```shell= conda install tensorflow-gpu conda install keras ``` ## 結局、いろいろやってみたがダメ。condaの仮想環境を一旦削除後に再作成したがダメ。 ## pythonの仮想環境を追加して再構築してみたがダメ。 ## pythonのバージョンを `3.9` に上げて、Pythonの仮想環境を使用すると正常に動作した。※Anacondaの仮想環境のバージョンを上げただけではダメ。 ```shell= python -V Python 3.9.5 ``` ```shell= pip list Package Version ----------------------- ------------------- absl-py 0.13.0 astunparse 1.6.3 cachetools 4.2.2 certifi 2021.5.30 charset-normalizer 2.0.3 flatbuffers 1.12 gast 0.4.0 google-auth 1.33.1 google-auth-oauthlib 0.4.4 google-pasta 0.2.0 grpcio 1.34.1 h5py 3.1.0 idna 3.2 Keras 2.4.3 keras-nightly 2.5.0.dev2021032900 Keras-Preprocessing 1.1.2 Markdown 3.3.4 numpy 1.19.5 oauthlib 3.1.1 opt-einsum 3.3.0 pip 21.1.3 protobuf 3.17.3 pyasn1 0.4.8 pyasn1-modules 0.2.8 PyYAML 5.4.1 requests 2.26.0 requests-oauthlib 1.3.0 rsa 4.7.2 scipy 1.7.0 setuptools 56.0.0 six 1.15.0 tensorboard 2.5.0 tensorboard-data-server 0.6.1 tensorboard-plugin-wit 1.8.0 tensorflow 2.5.0 tensorflow-estimator 2.5.0 termcolor 1.1.0 typing-extensions 3.7.4.3 urllib3 1.26.6 Werkzeug 2.0.1 wheel 0.36.2 wrapt 1.12.1 ``` ## tensorflowのバージョンを下げてみる > https://pypi.org/project/tensorflow/#history 以下の組み合わせであれば、正常に動作する。 ```shell= conda create -n test activate test conda install python=3.8 pip install tensorflow==2.4.2 pip install keras==2.4.3 ``` ###### tags: `Python` `keras` `TensorFlow` `AttributeError`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up