zoukankan      html  css  js  c++  java
  • 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.
    '
            '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
    
  • 相关阅读:
    Java 基础 | 命名和运算
    JSON类型解析
    Python 实例方法、类方法、静态方法的区别与作用
    Python中logging模块的基本用法
    python中局部变量和全局变量
    C# 中 引用类型和值类型
    VS2008+SVN插件的使用
    使用linq to xml 怎么减小内存消耗
    linq to xml 中SaveOptions和LoadOptions的介绍
    C# 中==和Equals方法在引用类型中的区别
  • 原文地址:https://www.cnblogs.com/zdoubly/p/13769443.html
Copyright © 2011-2022 走看看