0

I try to connect MySQL with Django. For that, I need to install mysqlclient with this command:

pip install mysqlclient

but it's giving me this following error

> /usr/local/lib/python2.7/dist-packages/pip-18.0-py2.7.egg/pip/_vendor/requests/__init__.py:83:
> RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may
> cause slowdown.   warnings.warn(warning, RequestsDependencyWarning)
> Collecting mysqlclient   Using cached
> https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz
> Installing collected packages: mysqlclient   Running setup.py install
> for mysqlclient ... error
>     Complete output from command /usr/bin/python -u -c "import setuptools,
> tokenize;__file__='/tmp/pip-install-kP3VWP/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-record-Znr67C/install-record.txt --single-version-externally-managed --compile:
>     running install
>     running build
>     running build_py
>     creating build
>     creating build/lib.linux-x86_64-2.7
>     copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
>     creating build/lib.linux-x86_64-2.7/MySQLdb
>     copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
>     copying MySQLdb/compat.py -> build/lib.linux-x86_64-2.7/MySQLdb
>     copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
>     copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
>     copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
>     copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
>     copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
>     creating build/lib.linux-x86_64-2.7/MySQLdb/constants
>     copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
>     copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
>     copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
>     copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
>     copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
>     copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
>     copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
>     running build_ext
>     building '_mysql' extension
>     creating build/temp.linux-x86_64-2.7
>     x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
>     _mysql.c:37:20: fatal error: Python.h: No such file or directory
>     compilation terminated.
>     error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
>     
>     ---------------------------------------- Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-kP3VWP/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-record-Znr67C/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-kP3VWP/mysqlclient/

When I try this command:

pip3 install mysqlclient

its giving me this following error

Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.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-13zxsnds/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmp5ktn63uopip-wheel- --python-tag cp35:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  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 ... done
Successfully installed mysqlclient-1.3.13
You are using pip version 8.1.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

How can I install mysqlclient in Linux mint and connect MySQL with Django 2 using pip3 ?

4
  • 2
    Possible duplicate of fatal error: Python.h: No such file or directory Commented Aug 13, 2018 at 12:02
  • 1
    To fix the second error, install wheel: either pip3 install wheel --user for the current user only, or apt install python3-wheel system-wide. Commented Aug 13, 2018 at 12:03
  • 1
    Note that Django 2.0 does not support python 2! Commented Aug 13, 2018 at 13:54
  • stackoverflow.com/questions/26664102/… Commented Aug 14, 2018 at 20:10

1 Answer 1

4

python2:

sudo apt-get install python-dev libmysqlclient-dev

if you use python3:

sudo apt-get install python3-dev

on ubuntu

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

1 Comment

Your code solved my one week pain of mysqlclient issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.