-1

There are a lot of similar question but all of them has different solution. And none of them work for me.

I'm trying to install Mysql connector for Django project but it gives below error.

First I have installed latest version of Django. Then install mysql with below code

brew install mysql - Worked fine.

Then this is the code which I'm trying install connector.

pip3 mysql-python. Was using easy_install mysql-python before but both of them are not working.

Python Version: 3.8.0

Django Version: 2.2.7

MySql Version: 8.0.18

pip3 mysql-python gives this error:

Collecting mysql-python Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip ERROR: Command errored out with exit status 1: command: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/pip-egg-info cwd: /private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/ Complete output (7 lines): Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/setup.py", line 13, in <module> from setup_posix import get_config File "/private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-4nmg9waj/mysql-python/setup_posix.py", line 2, in <module> from ConfigParser import SafeConfigParser ModuleNotFoundError: No module named 'ConfigParser' ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Cem
  • 83
  • 9
  • try the steps here for Macs, it helped me before: https://ruddra.com/posts/install-mysqlclient-macos/ it suggests installing mysqlclient rather than mysql-python – Edoardo Facchinelli Nov 30 '19 at 22:45
  • Does this answer your question? [pip3 install mysql-python failed with error code 1 in /tmp/pip-install-4nev4id4/mysql-python/](https://stackoverflow.com/questions/53743576/pip3-install-mysql-python-failed-with-error-code-1-in-tmp-pip-install-4nev4id4) – phd Nov 30 '19 at 22:59
  • https://stackoverflow.com/search?q=%5Bpip%5D+%5Bmysql-python%5D+ModuleNotFoundError%3A+No+module+named+%27ConfigParser%27 – phd Nov 30 '19 at 22:59
  • Hi @EdoardoFacchinelli, i tried step by step but it failed on `pip install mysqlclient`. I also tried with `pip3` but didn't work. Error message is too long. Here is some part: `Complete output (12 lines): /bin/sh: mysql_config: command not found /bin/sh: mariadb_config: command not found /bin/sh: mysql_config: command not found Traceback (most recent call last): File "", line 1, in File "/private/var/folders/6n/d2t3k0sd4l1d78bgk_ll5psm0000gn/T/pip-install-pzdweaop/mysqlclient/setup.py", line 16, in metadata, options` – Cem Nov 30 '19 at 23:35
  • @EdoardoFacchinelli I'm finally able to run `pip install mysqlclient` after using `--force` in step= `brew link --overwrite mysql-connector-c`. But i still have problem with connecting to db. The error code is too long for comment but it ends with: `raise ImproperlyConfigured("settings.DATABASES is improperly configured. " django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.` – Cem Dec 01 '19 at 07:00
  • That looks like a settings problem now, try checking the settings.py file variable DATABASES, documentation is here for the usual values: https://docs.djangoproject.com/en/2.2/ref/databases/#connecting-to-the-database – Edoardo Facchinelli Dec 01 '19 at 11:49
  • Yes, I deleted D of Database accidentally in setting file. It fixed after that,I got another error same with [link](https://stackoverflow.com/questions/55657752/django-installing-mysqlclient-error-mysqlclient-1-3-13-or-newer-is-required) and after updating base and operation file, i got `cryptography is required for sha256_password or caching_sha2_password` error and after updating password with same exact query that i did during installing MySQL and it worked this time and Django migrated changes on mysql db finally. Thanks a lot. – Cem Dec 01 '19 at 21:32
  • I just created a new project and tried same steps on it. `pip install mysqlclient` is working but I have `python3` so I need `pip3 install mysqlclient` run but it is not working on new project. I'm able to run old project. So basically, I have still same issue with new project. Do you have any idea why it happens? – Cem Dec 02 '19 at 06:24

2 Answers2

0

You're installing the wrong lib, you should be using mysqlclient.

pip install mysqlclient

I have a django project on my Mac using it.

Edit

You should be using virtualenv when installing pip packages.

Eliakin Costa
  • 930
  • 6
  • 16
  • You should be using a [virtualenv](https://sourabhbajaj.com/mac-setup/Python/virtualenv.html).@Cem – Eliakin Costa Dec 01 '19 at 00:02
  • Well, I've uninstalled mysql, pip, brew and reinstalled all and still have same problem. Btw; I'm able to create Django project and can create database on mysql. But `pip3 install mysqlclient` is giving error and I get error from my Django project when running `python3 manage.py migrate` – Cem Dec 01 '19 at 01:24
  • Did you try to setup a virtuaenv?@Cem – Eliakin Costa Dec 01 '19 at 01:34
  • Is MySQL installed on your system? – ja408 Dec 01 '19 at 02:53
  • Yes. I'm able to start server. `CemPc:~ cem$ mysql.server start Starting MySQL SUCCESS! CemPc:~ cm$ 2019-12-01T06:05:10.6NZ mysqld_safe A mysqld process already exists` Can I remove everything, and which version of python, django and mysql can install from fresh? – Cem Dec 01 '19 at 06:06
  • I've installed `virtualenv` also but after that `pip3 install mysqlclient` again didn't work – Cem Dec 01 '19 at 06:33
0

This command worked for me

pip3 install mysqlclient==1.4.2.post1