MacOS Python error: ModuleNotFoundError: No module named 'keras'

When executing the script, import the package from keras.preprocessing.image import ImageDataGenerator, and report an error ModuleNotFoundError: No module named 'keras', then pip installs keras:

pip install keras

The installation failed and still reported an error:

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied

Install with sudo:

​​​​​​​sudo python -m pip install keras

keras installed successfully!

However, an error is still reported when executing the script: ModuleNotFoundError: No module named 'tensorflow'

pip install tensorflow:

sudo python -m pip install tensorflow

The installation failed with an error:

ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow

Install tensorflow on MacOS :

1. Set up(arm64)

bash ~/miniconda.sh -b -p $HOME/miniconda
source ~/miniconda/bin/activate
conda install -c apple tensorflow-deps

2.Install base TensorFlow

python -m pip install tensorflow-macos

3.Install tensorflow-metal plug-in

python -m pip install tensorflow-metal

success!

Guess you like

Origin blog.csdn.net/daydayup858/article/details/129322817