macos django 导入使用MySQL错误 django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient? Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib

error :django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?

  • 启动django后突然发现这个错误
排查思路:

查看 django mysqlclient 相关源码,

try:
    import MySQLdb as Database
except ImportError as err:
    raise ImproperlyConfigured(
        'Error loading MySQLdb module.\n'
        'Did you install mysqlclient?'
) from err

所以只要你导入失败就会有这个异常,有两种可能,一种是没安装,另一种是导入的包有问题


1. 确定包是否安装 mysqlclient

╰>pip3 list
Package                       Version
----------------------------- ---------
.......
mysqlclient                   1.4.4
.......
2. 手动导入MySQL 是否报错

所以尝试:
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
    from . import _mysql
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
  Reason: image not found
 
3. 这个是和ssl 相关的内容报错,

终端运行:
brew switch openssl 1.0.2s
问题解决

参考: https://stackoverflow.com/questions/59006602/dyld-library-not-loaded-usr-local-opt-openssl-lib-libssl-1-0-0-dylib
posted @   呦吼吼吼~  阅读(420)  评论(0编辑  收藏  举报
编辑推荐:
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
阅读排行:
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 【非技术】说说2024年我都干了些啥
点击右上角即可分享
微信分享提示