0

EDIT: Problem resolved. I was able to finally figure out the problem with some help from another student in the Udemy class along with the answer from Isaac_R here. I had to edit my .bash_profile with the following two lines of code and I am able to install MySQLdb and it is working as intended now. Here are the two lines I added to my .bash_profile

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

EDIT #2: I just started another mysql project in a new file, I had to run pip3 install mysqlclient before I could install mysqldb, just a heads up to someone who may have this issue like I did.

I am totally new to coding so please excuse my potential ignorance, I am trying my best to learn something new and it was going well until I ran into this issue that I am unable to get passed. I am on a Mac with 10.15.4 in python3.8.2 trying to create a MySQL database in order to use in a blog I am attempting to build. I have installed the mysql client along with pip3 install flask-mysqldb. I get successful conformation of the install, here is where my problems start. In Atom I am using the command from ''flask_mysqldb import MySQL'' to which I receive the error of the following

Traceback (most recent call last):
  File "app.py", line 3, in <module>
    from flask_mysqldb import MySQL
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask_mysqldb/__init__.py", line 1,
 in <module>
    import MySQLdb
  File "IndentationError: unexpected indent
(venv) tylernelson@Tylers-MacBook-Air My Project % python3 app.py
Traceback (most recent call last):
  File "app.py", line 3, in <module>
    from flask_mysqldb import MySQL
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask_mysqldb/__init__.py", line 1,
 in <module>
    import MySQLdb
  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: @rpath/libmysqlclient.21.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-3
8-darwin.so
Reason: image not found"

I am able to post my entire (all be it super short) code file also if that will help resolve the problem. Thank you so much for your ideas and help!

tylern012
  • 1
  • 3
  • does [this](https://stackoverflow.com/questions/51002735/python-mysqldb-err-on-my-mac-library-not-loaded-rpath-libmysqlclient-21-dylib) help? – danblack Apr 22 '20 at 04:16
  • It gave me a few more options to try but unfortunately has not solved my issue yet. it did however bring up something new when I tried the command " sudo pip3 install flask-mysqldb. I got this in return and I don't know if it matters or not. WARNING: The directory '/Users/tylernelson/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Thank you for your help. – tylern012 Apr 22 '20 at 15:04

1 Answers1

0

I went thru the same issue, I found the best solutions within this question:

Python mysqldb: Library not loaded: libmysqlclient.18.dylib

I will recommend you to go thru all the options listed there, in my case run the command

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

solved my issues, most of the time when mysql gets installed the mysql directory should be renamed to just mysql.

Isaac_R
  • 53
  • 6
  • Thank you for your response, I have edited my .bash_profile to include that line of code and unfortunately it is still not working. Here is what I have in the .bash_profile currently. `# Setting PATH for Python 3.8 # The original version is saved in .bash_profile.pysave # PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}" export PATH # export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH` – tylern012 Apr 27 '20 at 16:42