9

I want to run a Django application in PyCharm which works on MySQL DB.

I am unable to connect my program to the database.

When I am trying to install MySQLclient or MySQL-python I am getting the error:

Failed building wheel for MySQLclient

Please help me out in connecting my Django program with MySQL database.

Patrick
  • 4,472
  • 9
  • 54
  • 85
Swathi Pantala
  • 315
  • 1
  • 5
  • 13

3 Answers3

9

Edit

Please try installing the .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/. This works every time. Just type pip install MySQL_python‑1.2.5‑cp27‑none‑win32.whl in the terminal.

Original Answer

I had the same issue. You might find these steps helpful.

  1. Make sure you are in an activated virtualenv when you are installing anything through pip.
  2. Before you install anything, type pip list in the terminal to see what you have installed in the virtualenv. It should have wheel, setuptools and pip.
  3. This is the part that helped me, type pip install mysqlclient==1.3.9 or whatever version you want to install. This needs to happen before you install django.
  4. Hopefully, it works and you can go ahead and install Django.

If these steps didn't work out for you, try installing MySQL-Python through the executable file here https://pypi.python.org/pypi/MySQL-python/1.2.5.

But this will only install mysql-python for you in the system. You can try pip list outside virtualenv to see if mysql-python is installed. If it is installed, then you have update this post so we can figure out a solution.

In the meantime some other fixes are:

  • Can't install mysql-python (newer versions) in Windows
  • Install Visual C++ for Python and add the bin folder to the PATH environment variable.
  • Make sure the mysql service is running in the background or is installed in your system by running mysql commands through the terminal.
  • Sometimes, two different instances of mysql service might cause this error i.e. if you have installed mysql server or any other product multiple times in the past, you might have to get rid of the ports the past services used. In this case, do a fresh installation of mysql server and add the ~\bin path to the PATH environment variable.
MarredCheese
  • 9,495
  • 5
  • 59
  • 63
Gaurav Vasudev
  • 117
  • 1
  • 10
  • 1
    When running `pip install MySQL_python‑1.2.5‑cp27‑none‑win32.whl` I get `MySQL_python‑1.2.5‑cp27‑none‑win32.whl is not a valid wheel filename.` – jmona789 Apr 04 '19 at 18:55
  • @jmona789 hi, i know its too old to ask but i have the same issue can you tell how does it get solved? – Habib Rehman Apr 06 '20 at 17:54
4

I had the same problem. I then uninstalled my python. Downloaded the python 3.6.5. then used a command from

Python 3.7, Failed building wheel for MySql-Python

the command is pip install mysqlclient==1.3.12

Shamsul Arefin Sajib
  • 1,435
  • 15
  • 19
  • Thanks for the tip. Version 1.3.12 works. But why is having python uninstalled relevant? – Wtower Jun 06 '19 at 13:45
  • After a lot of digging, it appeared to me that, python 3.6.5 and mysql 1.3.12 matches. Unfortunately, using other python version such as 3.6,3.7, I was having a hard time finding appropriate mysql version. – Shamsul Arefin Sajib Jun 09 '19 at 04:41
0

In case you are using sqlalchemy(which implicitly uses mysql-python) to connect to a MySQL database, updating it using pip install sqlalchemy --upgrade might do the trick and while creating a connection using an engine the syntax should be:

from sqlalchemy import create_engine


HOST = "your_host_name.host.com"
USER = "your_username"
PASSCODE = "your_passcode"
DATABASE = "name_of_database"

engine = create_engine(f'mysql+mysqldb://{USER}:{PASSCODE}@{HOST}/{DATABASE}')
angwalt
  • 41
  • 2