0

I'm using mysql with django for the first time. Both are installed, I can use mysql in the workbench or command prompt, however when I tried migrations in django, it can't find the mysqldb module, cut most of it out, see below:

Traceback (most recent call last):

File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)

File "C:\Users\jerro\Desktop\djangoEnv\lib\site-packages\django\db\backends\mysql\base.py", line 28, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

So i've been trying to use pip install mysql-python and can't do it. I've installed mysql-connector, annaconda, and tried many other suggestions on this and google, no luck. It gives me the error below:

running build_ext
building '_mysql' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
C:\Users\jerro\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -IC:\Python27\include -Ic:\users\jerro\desktop\djangoenv\PC /Tc_mysql.c /Fobuild\temp.win-amd64-2.7\Release\_mysql.obj /Zl
_mysql.c
_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\\Users\\jerro\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2

----------------------------------------


Command "c:\users\jerro\desktop\djangoenv\scripts\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\jerro\\appdata\\local\\temp\\pip-build-_da1js\\MySQL-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\jerro\appdata\local\temp\pip-kqvwr3-record\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\jerro\desktop\djangoenv\include\site\python2.7\MySQL-python" failed with error code 1 in c:\users\jerro\appdata\local\temp\pip-build-_da1js\MySQL-python\

Nothing i've done or tried has worked, any suggestions? i'm using windows10


Update, I finally was able to get pip mysql-python installed, now the only error I get is the no module named mysqldb when I try to makemigrations. mysql-connector, mysqlclient is installed, still no luck.

2 Answers 2

1

sometimes pip install mysqlclient command doesn't work so follow these steps:

1) search unofficial python binaries or go to https://www.lfd.uci.edu/~gohlke/pythonlibs/ and search(ctrl+f)on that page for mysqlclient

2) check your python version on machine and download the whl file appropriate for your downloaded python version like type python in command prompt and you will get your python version

>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

this is python 3.7.3 version and works on 32 bit    

so the whl file will be mysqlclient-1.4.4-cp37-cp37m-win32.whl
python 3.7.3 = cp37 and 32 bit is win32

3) download that file and type following code in your environment or where you downloaded the whl file >pip install mysqlclient-1.4.4-cp37-cp37m-win32.whl

hope this will work

Sign up to request clarification or add additional context in comments.

1 Comment

Works for me, instead having to install VS buildtools.
0

Head over to Mysql and install Connector. This should fix your problem.

1 Comment

Still nothing, I've pip install mysql-connector before but neither that nor this has done any good.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.