0
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libmysqlclient.21.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

After entering from app import db and db.create_all() in terminal above error comes

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
Jay Patel
  • 37
  • 10
  • did you install database MySQL ? It may need also some of Python's modules to work with MySQL - ie. `mysql-connector` – furas Mar 04 '20 at 06:04
  • I am using SQLAlchemy so don't need mysql-connector – Jay Patel Mar 04 '20 at 06:18
  • 1
    You need one of the MySQL DB-API drivers, be it mysql-connector, mysql-python aka MySQLdb, or pymysql. SQLAlchemy does not talk directly to the DB itself. – Ilja Everilä Mar 04 '20 at 06:25
  • Have you checked https://stackoverflow.com/questions/53590645/library-not-loaded-rpath-libmysqlclient-21-dylib-reason-image-not-found-djang, https://stackoverflow.com/questions/34536914/pythons-mysqldb-can-t-find-libmysqlclient-dylib-with-homebrewed-mysql, https://stackoverflow.com/questions/51002735/python-mysqldb-err-on-my-mac-library-not-loaded-rpath-libmysqlclient-21-dylib, and https://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib? – Ilja Everilä Mar 04 '20 at 06:26
  • I have successfully disable SIP, now what is the next step, when I run following command it says file already exist. ```sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib``` – Jay Patel Mar 04 '20 at 07:05
  • I did most of the above still showing same error – Jay Patel Mar 04 '20 at 07:32

1 Answers1

0

Step 1: Create virtual environment Step 2: Install all necessary module e.g. Flask, SQLAlchemy, however, you won't be able to install MySQLDB so instead of that use pip install pymysql Step 3: app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:Vrishab2145@localhost/testOne' In step 3, must add mysql+pymysql

Hureyy..... It worked for me Important is creating virtual environment. You don't need to go through nasty SSL and other things

Jay Patel
  • 37
  • 10