When connected with today python mysql error:
File "/Users/zhbink/Documents/GitHub/Scrapy/ArticleSpider/ArticleSpider/pipelines.py", line 5, in <module>
import MySQLdb
File "/Users/zhbink/opt/anaconda3/envs/django/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: dlopen(/Users/zhbink/opt/anaconda3/envs/django/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libmysqlclient.21.dylib
Referenced from: /Users/zhbink/opt/anaconda3/envs/django/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
Reason: image not found
Library use is MySQLdb
, then consider the possibility that I am using this python version is not compatible with the library.
After access to information that MySQLdb
is not compatible py3.5 later.
Solution:
Use pymysql
instead ofMySQLdb
step:
-
Installation pymysql:
pip install pymysql
-
Open the project __init__.py, or directly at the very beginning of the current py file and add the following:
import pymysql
pymysql.install_as_MySQLdb()