I am trying to connect to mysql with python 3.6.9 and django 3.0.1 on linux lubuntu
mysql Ver 14.14 Distrib 5.7.28, for Linux (i686) using EditLine wrapper
Currently I'm getting this error message when I run the django server although I have tried to install a mysql client:
django.core.exceptions.ImproperlyConfigured: Error loading >MySQLdb module.
Did you install mysqlclient?
dpkg --get-selections | grep mysql
libmysqlclient20:i386 install
mysql-client-5.7 install
mysql-client-core-5.7 install
mysql-common install
mysql-server install
mysql-server-5.7 install
mysql-server-core-5.7 install
python-mysqldb install
MySQLdb is not it seems supported for python 3 according to this: https://pypi.org/project/MySQL-python/
Is mysql not supported for Django/python 3 yet? I am struggling to find relevant info. after much searching, I have seen many questions on stack overflow about similar issues but with earlier versions of all the software.
I have installed pymysql which successfully connects to mysql and retrieves data, but this doesn't seem to be useful for Django.
Edit: I tried pip3 install mysqlclient but got this output:
pip3 install mysqlclient
Collecting mysqlclient Using cached https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz Building wheels for collected packages: mysqlclient Running setup.py bdist_wheel for mysqlclient ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-2rl7qhom/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpvr8f4qvqpip-wheel- --python-tag cp36: running bdist_wheel running build running build_py creating build creating build/lib.linux-i686-3.6 creating build/lib.linux-i686-3.6/MySQLdb copying MySQLdb/__init__.py -> build/lib.linux-i686-3.6/MySQLdb copying MySQLdb/_exceptions.py -> build/lib.linux-i686-3.6/MySQLdb copying MySQLdb/compat.py -> build/lib.linux-i686-3.6/MySQLdb copying MySQLdb/connections.py -> build/lib.linux-i686-3.6/MySQLdb copying MySQLdb/converters.py -> build/lib.linux-i686-3.6/MySQLdb copying MySQLdb/cursors.py -> build/lib.linux-i686-3.6/MySQLdb copying MySQLdb/release.py -> build/lib.linux-i686-3.6/MySQLdb copying MySQLdb/times.py -> build/lib.linux-i686-3.6/MySQLdb creating build/lib.linux-i686-3.6/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-3.6/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-3.6/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.linux-i686-3.6/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.linux-i686-3.6/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-3.6/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-3.6/MySQLdb/constants running build_ext building 'MySQLdb._mysql' extension creating build/temp.linux-i686-3.6 creating build/temp.linux-i686-3.6/MySQLdb i686-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g
-fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 -I/usr/include/mysql -I/usr/include/python3.6m -c MySQLdb/_mysql.c -o build/temp.linux-i686-3.6/MySQLdb/_mysql.o i686-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions
-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-i686-3.6/MySQLdb/_mysql.o -lmysqlclient -lpthread -lz
-lm -lrt -latomic -lssl -lcrypto -ldl -o build/lib.linux-i686-3.6/MySQLdb/_mysql.cpython-36m-i386-linux-gnu.so /usr/bin/ld: cannot find -lssl /usr/bin/ld: cannot find -lcrypto collect2: error: ld returned 1 exit status error: command 'i686-linux-gnu-gcc' failed with exit status 1
---------------------------------------- Failed building wheel for mysqlclient Running setup.py clean for mysqlclient Failed to build mysqlclient Installing collected packages: mysqlclient Running setup.py install for mysqlclient ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-2rl7qhom/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install
--record /tmp/pip-p7jgo6pz-record/install-record.txt --single-version-externally-managed --compile --user --prefix=:
running install
running build
running build_py
creating build
creating build/lib.linux-i686-3.6
creating build/lib.linux-i686-3.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-i686-3.6/MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.linux-i686-3.6/MySQLdb
copying MySQLdb/compat.py -> build/lib.linux-i686-3.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-i686-3.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-i686-3.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-i686-3.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-i686-3.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-i686-3.6/MySQLdb
creating build/lib.linux-i686-3.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-3.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-3.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-i686-3.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-i686-3.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-3.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-3.6/MySQLdb/constants
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.linux-i686-3.6
creating build/temp.linux-i686-3.6/MySQLdb
i686-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 -I/usr/include/mysql -I/usr/include/python3.6m -c MySQLdb/_mysql.c -o build/temp.linux-i686-3.6/MySQLdb/_mysql.o
i686-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-i686-3.6/MySQLdb/_mysql.o -lmysqlclient -lpthread -lz
-lm -lrt -latomic -lssl -lcrypto -ldl -o build/lib.linux-i686-3.6/MySQLdb/_mysql.cpython-36m-i386-linux-gnu.so
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
error: command 'i686-linux-gnu-gcc' failed with exit status 1
---------------------------------------- Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-2rl7qhom/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install
--record /tmp/pip-p7jgo6pz-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-2rl7qhom/mysqlclient/
Edit: I found a related ticket which enabled me to resolve this:
"cannot find -lssl; cannot find -lcrypto" when installing mysql-python?
sudo apt-get install libssl-dev
and then repeated:
'pip3 install mysqlclient'
this time with no errors. Not sure if extra steps preceding two steps in this link were necessary or not but for the benefit of others you might need to follow those steps: