Am Trying to connect to my mysql db from django app. I get the below error during migration:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?
I've already installed mysqlclient as below:
Requirement already satisfied: mysqlclient in /usr/local/lib/python3.7/site-packages [1.4.2.post1]
I've also tried with pymysql and adding below code to ini.py file:
import pymysql
pymysql.install_as_MySQLdb[]
Gives me some other errors. What could be wrong?
Python 3.7 , mysql 5.7 and Django 2.2 are my setup versions.
asked Aug 8, 2019 at 8:45
7
I had the same issue. Running the below command fixed it for me.
pip install --force-reinstall --ignore-installed --no-binary :all: mysqlclient
answered Sep 23, 2019 at 2:13
I had the same issue. The thing that worked for me is the following:
//stackoverflow.com/a/54521244/12497648,
except when I did brew install mysql-client
I got the message Warning: mysql-client 5.7.23_1 is already installed and up-to-date
To reinstall 5.7.23_1, run "brew reinstall mysql-client"
so I ran brew reinstall mysql-client
after which I continued with the instructions from the link above [export PATH... etc.]
[also don't forget to do the
pip wheel mysqlclient
/ pip install mysqlclient
]
answered Dec 7, 2019 at 20:50
answered Jun 18, 2020 at 10:01
M3RSM3RS
5,9365 gold badges32 silver badges43 bronze badges
Python: 3.9.5
mysql: 8.0.25
Trying to install mysqlclient for setting up connection with django but failing with the below output:
Collecting mysqlclient
Using cached mysqlclient-2.0.3.tar.gz [88 kB]
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
ERROR: Command errored out with exit status 1:
command: /Users/mketan/Documents/diit/diit_env/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/setup.py'"'"'; __file__='"'"'/private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/setup.py'"'"';f = getattr[tokenize, '"'"'open'"'"', open][__file__] if os.path.exists[__file__] else io.StringIO['"'"'from setuptools import setup; setup[]'"'"'];code = f.read[].replace['"'"'\r\n'"'"', '"'"'\n'"'"'];f.close[];exec[compile[code, __file__, '"'"'exec'"'"']]' install --record /private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-record-3wl14yep/install-record.txt --single-version-externally-managed --compile --install-headers /Users/b0223621/Documents/diit/diit_env/include/site/python3.9/mysqlclient
cwd: /private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/
Complete output [43 lines]:
mysql_config --version
['8.0.25']
mysql_config --libs
['-L/opt/homebrew/Cellar/mysql/8.0.25_1/lib', '-lmysqlclient', '-lz', '-lzstd', '-lssl', '-lcrypto', '-lresolv']
mysql_config --cflags
['-I/opt/homebrew/Cellar/mysql/8.0.25_1/include/mysql']
ext_options:
library_dirs: ['/opt/homebrew/Cellar/mysql/8.0.25_1/lib']
libraries: ['mysqlclient', 'zstd', 'resolv']
extra_compile_args: ['-std=c99']
extra_link_args: []
include_dirs: ['/opt/homebrew/Cellar/mysql/8.0.25_1/include/mysql']
extra_objects: []
define_macros: [['version_info', "[2,0,3,'final',0]"], ['__version__', '2.0.3']]
running install
running build
running build_py
creating build
creating build/lib.macosx-10.9-universal2-3.9
creating build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
creating build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.macosx-10.9-universal2-3.9
creating build/temp.macosx-10.9-universal2-3.9/MySQLdb
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/bzip2/include -I/opt/homebrew/opt//include -Dversion_info=[2,0,3,'final',0] -D__version__=2.0.3 -I/opt/homebrew/Cellar/mysql/8.0.25_1/include/mysql -I/Users/b0223621/Documents/diit/diit_env/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-universal2-3.9/MySQLdb/_mysql.o -std=c99
gcc -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -g -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/bzip2/lib -L/opt/homebrew/opt//lib -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/bzip2/include -I/opt/homebrew/opt//include build/temp.macosx-10.9-universal2-3.9/MySQLdb/_mysql.o -L/opt/homebrew/Cellar/mysql/8.0.25_1/lib -lmysqlclient -lzstd -lresolv -o build/lib.macosx-10.9-universal2-3.9/MySQLdb/_mysql.cpython-39-darwin.so
ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 [use -v to see invocation]
error: command '/usr/bin/gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /Users/b0223621/Documents/diit/diit_env/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/setup.py'"'"'; __file__='"'"'/private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/setup.py'"'"';f = getattr[tokenize, '"'"'open'"'"', open][__file__] if os.path.exists[__file__] else io.StringIO['"'"'from setuptools import setup; setup[]'"'"'];code = f.read[].replace['"'"'\r\n'"'"', '"'"'\n'"'"'];f.close[];exec[compile[code, __file__, '"'"'exec'"'"']]' install --record /private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-record-3wl14yep/install-record.txt --single-version-externally-managed --compile --install-headers /Users/mketan/Documents/diit/diit_env/include/site/python3.9/mysqlclient Check the logs for full command output.