美文网首页
mysqlclient修复image not found

mysqlclient修复image not found

作者: leejnull | 来源:发表于2020-02-24 22:29 被阅读0次

    Django项目要用到mysql,安装完mysqlclient之后,启动项目报错

    INFO Watching for file changes with StatReloader
    Exception in thread django-main-thread:
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
        import MySQLdb as Database
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/MySQLdb/__init__.py", line 18, in <module>
        from . import _mysql
    ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-darwin.so, 2): Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
      Referenced from: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-darwin.so
      Reason: image not found
    ......
    

    后面部分省略,主要看这部分,提示找不到libmysqlclient.20.dylib,之前为了安装mysqlclient,折腾了一大堆,brew update && brew upgrade,mysql又重新装了一遍,可能是由于这些原因导致的。

    打印显示该目录下有一个libmysqlclient.21.dylib

    -rw-r--r--    1 lijun  staff   7.0M  2 24 22:11 libmysqlclient.21.dylib
    -r--r--r--    1 lijun  staff   7.7M 12 10 04:11 libmysqlclient.a
    lrwxr-xr-x    1 lijun  staff    23B 12 10 04:11 libmysqlclient.dylib -> libmysqlclient.21.dylib
    -r--r--r--    1 lijun  staff   683K  2 24 21:48 libmysqlharness.1.dylib
    -r--r--r--    1 lijun  staff   7.8M  2 24 21:48 libmysqlrouter.1.dylib
    -r--r--r--    1 lijun  staff   254K  2 24 21:48 libmysqlrouter_http.1.dylib
    -r--r--r--    1 lijun  staff   9.5K 12 10 04:11 libmysqlservices.a
    drwxr-xr-x   13 lijun  staff   416B 12 10 04:11 mysqlrouter
    drwxr-xr-x    3 lijun  staff    96B  2 24 21:48 pkgconfig
    drwxr-xr-x  105 lijun  staff   3.3K 12 10 04:11 plugin
    

    索性想能不能加一个指向libmysqlclient.21.dylib的软连接libmysqlclient.20.dylib

    ln -sfv /usr/local/opt/mysql/lib/libmysqlclient.21.dylib /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
    

    重新运行项目

    python3.8 manage.py runserver                                                                                                          [22:11:52]
    INFO Watching for file changes with StatReloader
    Performing system checks...
    
    System check identified no issues (0 silenced).
    
    You have 20 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, book, contenttypes, crawler, sessions, user.
    Run 'python manage.py migrate' to apply them.
    
    February 24, 2020 - 22:14:58
    Django version 3.0.3, using settings 'bookstore.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CONTROL-C.
    

    OK,解决~

    相关文章

      网友评论

          本文标题:mysqlclient修复image not found

          本文链接:https://www.haomeiwen.com/subject/zhkgqhtx.html