使用CiFAR10、PyCharm/Python及pyplot加载图片遇SSL证书验证失败求助
Hey there, let's tackle these two issues you're facing step by step!
1. Resolving the SSL Certificate Verification Failed Error
The error you're hitting is super common on macOS with Python 3.8+, where the default SSL certificates are outdated or missing. Here are three solid solutions to fix it:
Option 1: Manually Download the Dataset (Most Reliable)
Skip the automatic download entirely by grabbing the dataset yourself:
- Get the CIFAR-10 archive (
cifar-10-python.tar.gz) from the official source - Drop it in a folder within your project (like
./datasets/) - Update your
load_data()call to point to the local file:(X_train, y_train), (X_test, y_test) = cifar10.load_data(path='./datasets/cifar-10-python.tar.gz')
Option 2: Temporarily Disable SSL Verification (Quick Fix)
If you need a fast workaround (note: this isn't ideal for long-term use due to security risks), add this at the very top of your code:
import ssl # Bypass SSL certificate verification temporarily ssl._create_default_https_context = ssl._create_unverified_context
Option 3: Update Python's SSL Certificates (MacOS-Specific Permanent Fix)
This fixes the root cause by updating your Python installation's certificates:
- Open Terminal
- Run this command (adjust the path if your Python 3.8 is installed in a different location):
/Applications/Python\ 3.8/Install\ Certificates.command
This script will refresh the root certificates, resolving the verification error for good.
2. Why You're Not Seeing "Using TensorFlow Backend"
The "Using TensorFlow backend" message only pops up when you're using the standalone Keras library. Since you're importing from tensorflow.python.keras (TensorFlow's built-in Keras implementation), this prompt won't show up. This is totally normal—your code is still using TensorFlow as the backend, so no action is needed here.
Your Original Error Log for Reference
/Users/muratuckan/PycharmProjects/TensorFlow/venv/bin/python /Users/muratuckan/PycharmProjects/TensorFlow/ImageRecognitionTrainer.py
Downloading data from https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1350, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
...
Exception: URL fetch failure on https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)Process finished with exit code 1
内容的提问来源于stack exchange,提问作者its_muri

