顾乔芝士网

持续更新的前后端开发技术栈

新安装的Python3.13无法install package

在macos系统上使用python3.13,执行pip install mysql-connector-python,提示错误

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1020)'))': /simple/mysql-connector-python/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1020)'))': /simple/mysql-connector-python/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1020)'))': /simple/mysql-connector-python/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1020)'))': /simple/mysql-connector-python/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1020)'))': /simple/mysql-connector-python/
Could not fetch URL https://pypi.org/simple/mysql-connector-python/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/mysql-connector-python/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1020)'))) - skipping
ERROR: Could not find a version that satisfies the requirement mysql-connector-python (from versions: none)
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1020)'))) - skipping
ERROR: No matching distribution found for mysql-connector-python

这个问题的根本原因是:你安装的 Python 缺少正确配置的受信任证书(certifi)


解决方法有两个,推荐顺序如下:

方法一(推荐,最简单直接):

Python 自带了一个脚本专门来安装证书,运行下面命令:

/Applications/Python\ 3.13/Install\ Certificates.command

注意:

  • 你可能需要根据你装的具体路径调整一下,比如 /Applications/Python 3.13/Install Certificates.command。
  • 直接打开终端,复制上面命令,回车运行。
  • 它会自动帮你下载并安装缺失的根证书。

然后再去执行:

pip install mysql-connector-python

应该就正常了。


方法二(如果方法一找不到脚本的话)

手动安装受信任证书:

  1. 升级 pip 并用 certifi:
  2. python3.13 -m ensurepip --upgrade python3.13 -m pip install --upgrade certifi
  3. 告诉 Python 使用 certifi 提供的证书文件,临时在 shell 中这样设置环境变量:
  4. export SSL_CERT_FILE=$(python3.13 -m certifi)
  5. 然后重新执行安装:
  6. pip install mysql-connector-python

如果想永久生效,可以把上面的 export SSL_CERT_FILE=... 写到你的 ~/.bash_profile、~/.zshrc 或其他你的 shell 配置文件里。

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言