9

I am trying to use django and use mysql as the database. i originally had it working just fine but i recently changed the name of the user account and that is where everything has gone wrong. I have used pip install mysqlclient but the error below is what i get. Is there a way to install mysqlclient another way?

I am using django's newest version and i am using visual code. Thank you

    ERROR: Command errored out with exit status 1:
     command: 'c:\users\jacob\appdata\local\programs\python\python37-32\python.e
xe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\JACOB
\\AppData\\Local\\Temp\\pip-install-ehb3yr50\\mysqlclient\\setup.py'"'"'; __file
__='"'"'C:\\Users\\JACOB\\AppData\\Local\\Temp\\pip-install-ehb3yr50\\mysqlclien
t\\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\JACOB\AppData\Local\Temp\pip-record
-hbel0tdu\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\JACOB\AppData\Local\Temp\pip-install-ehb3yr50\mysqlclient
\
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    creating build\lib.win32-3.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb
    creating build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constan
ts
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants

    copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\const
ants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win32-3.7
    creating build\temp.win32-3.7\Release
    creating build\temp.win32-3.7\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\
14.22.27905\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion
_info=(1,4,4,'final',0) -D__version__=1.4.4 "-IC:\Program Files (x86)\MySQL\MySQ
L Connector C 6.1\include\mariadb" -Ic:\users\jacob\appdata\local\programs\pytho
n\python37-32\include -Ic:\users\jacob\appdata\local\programs\python\python37-32
\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Too
ls\MSVC\14.22.27905\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual S
tudio\2019\Community\VC\Tools\MSVC\14.22.27905\include" "-IC:\Program Files (x86
)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits
\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include
\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.183
62.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "
-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /TcMySQL
db/_mysql.c /Fobuild\temp.win32-3.7\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SECURE
_NO_WARNINGS
    _mysql.c
    MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h'
: No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Comm
unity\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX86\\x86\\cl.exe' failed with exit
 status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\jacob\appdata\local\pro
grams\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sy
s.argv[0] = '"'"'C:\\Users\\JACOB\\AppData\\Local\\Temp\\pip-install-ehb3yr50\\m
ysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\JACOB\\AppData\\Local\\Temp\
\pip-install-ehb3yr50\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'
"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.clos
e();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\JA
COB\AppData\Local\Temp\pip-record-hbel0tdu\install-record.txt' --single-version-
externally-managed --compile Check the logs for full command output.
epinsten
  • 109
  • 1
  • 2
  • 7

4 Answers4

5

go to this site to download the package according to the python version. and use pip install filename like i have python 3.7.1 and download the file in red circle and open terminal where file downloaded and install that file e.g pip install mysqlclient-1.4.4-cp37-cp37m-win32.whl

and in setting file

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'shoping_cart',
        'HOST': 'localhost',
        'USER': 'root',
        'PASSWORD':'',
        'PORT': '3306',

    }
}

enter image description here

Sohail Ahmad
  • 7,309
  • 5
  • 27
  • 46
4

For Linux users

First, install the following dependencies:

sudo apt-get install python3.9-dev libmysqlclient-dev

# don't forget to change python version as per your virtual environment
# since I created my virtual environment with python3.9 that is why I 
# have mentioned the same version above

and then install the mysqlclient:

pip install mysqlclient
Ahtisham
  • 9,170
  • 4
  • 43
  • 57
0

it might be helpful to send us a 'pip freeze'. Also what's your version of python? Have you tried 'brew' instead of 'pip' installer?

Check this answer out: How to install Python MySQLdb module using pip?

David Raji
  • 16
  • 2
  • astroid==2.2.5 colorama==0.4.1 Django==2.2.4 isort==4.3.21 lazy-object-proxy==1.4.1 mccabe==0.6.1 mysql-client==0.0.1 mysql-connector-python==8.0.17 protobuf==3.9.1 pylint==2.3.1 PyMySQL==0.9.3 pytz==2019.2 six==1.12.0 sqlparse==0.3.0 typed-ast==1.4.0 utils==0.9.0 wrapt==1.11.2 this is my pip freeze i dont know what any of it means though. i am using python 3.7.4 – epinsten Aug 13 '19 at 19:39
  • it seems like you already have a mysql-client==0.0.1 . Don't worry about being new, a pip freeze is basically a list of all the installed modules that you have on your system. so it's a good way to see what you need and what you're missing. – David Raji Aug 14 '19 at 00:28
  • whenever i try and run django tho it says i dont have it thats where my problem lies – epinsten Aug 14 '19 at 12:57
  • ohh! okay, follow the steps in this video and you should be good: https://www.youtube.com/watch?v=6SnE0r7g2lE – David Raji Aug 14 '19 at 23:40
0

Yea I just double checked and you should be able to use the 'brew' installer. Basically you're missing the 'openssl' dependency. so you can alternatively just install that and then get mysql.

David Raji
  • 16
  • 2