Reason: image not found
Problem
通过 python manage.py runserver 0.0.0.0:80
启动 Django 时,报错:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Working/my_project/venv/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: /usr/local/opt/mysql@5.7/lib/libmysqlclient.20.dylib
Referenced from: /Working/my_project/venv/lib/python2.7/site-packages/_mysql.so
Reason: image not found
Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace instance at 0x10acf42d8>
Solution
这其实是因为在启动 Django 时,python interpreter 为了连接 MySQL,需要 libmysqlclient.20.dylib
文件,而去 /usr/local/opt/mysql@5.7/lib/libmysqlclient.20.dylib
路径下找时,未找到该文件。
而事实上,本机中其实有 libmysqlclient.20.dylib
文件的,我的这个文件位于 /usr/local/mysql-5.7.28-macos10.14-x86_64/lib/libmysqlclient.20.dylib
下。
# 直接创建软链接,有可能会出现因不存在特定文件夹,导致创建失败的情况
$ sudo ln -s /usr/local/mysql-5.7.28-macos10.14-x86_64/lib/libmysqlclient.20.dylib /usr/local/opt/mysql@5.7/lib/libmysqlclient.20.dylib
ln: /usr/local/opt/mysql@5.7/lib/libmysqlclient.20.dylib: No such file or directory
$ mkdir /usr/local/opt/mysql@5.7
$ cd /usr/local/opt/mysql@5.7
$ mkdir lib
$ sudo ln -s /usr/local/mysql-5.7.28-macos10.14-x86_64/lib/libmysqlclient.20.dylib /usr/local/opt/mysql@5.7/lib/libmysqlclient.20.dylib
再次启动 Django 时,一切正常。
Reference
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper