Failed building wheel for mysql-python - mysql

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.

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.
Make sure you are in an activated virtualenv when you are installing anything through pip.
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.
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.
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.

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

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}')

I found a solution to install mysqlclient on Windows 10 64 bit, Django version 3.10.0
Download preferred mysqlclient wheel for your OS/bit size. here :
https://pypi.tuna.tsinghua.edu.cn/simple/mysqlclient/
Point to the directory such as C:\Users\hp\Desktop\storefront\store from your prompt or terminal
install using pip i.e: C:\Users\hp\Desktop\storefront\store > pip install mysqlclient-2.1.0-cp310-cp310-win_amd64.whl

I hope this would help.I am running Python3.7 on windows 7 (32-bit). I had the same issue and tried using PIP commands from windows CLI. Although, my pip installation was successful but I was not able to add MYSQL or MYSQL-Connector-Python from Pycharm GUI. I used Pycharm Terminal for Below packages and was able to connect to MYSQL database.
Example:
(PTPT) C:\Windows\System32>pip3 install mysql-connector-python==8.0.29
Collecting mysql-connector-python==8.0.29
Downloading https://files.pythonhosted.org/packages/32/cd/1581bfe8f5ad7fd2aecdc499f0387227ad7912419384f9393b6205a764da/mysql_connector_python-8.0.29-py2.py3-none-any.whl (342kB)
|████████████████████████████████| 348kB 409kB/s
Requirement already satisfied: protobuf>=3.0.0 in c:\users\maghy\ptpt\lib\site-packages (from mysql-connector-python==8.0.29) (3.20.1)
Installing collected packages: mysql-connector-python
Found existing installation: mysql-connector-python 8.0.30
Uninstalling mysql-connector-python-8.0.30:
Successfully uninstalled mysql-connector-python-8.0.30
Successfully installed mysql-connector-python-8.0.29
WARNING: You are using pip version 19.3.1; however, version 22.2.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
pip install C:\Users\USER_NAME\Downloads\mysqlclient-1.4.6-cp37-cp37m-win32.whl
PYCHARM MYSQL PACKAGE

Related

Django - installing mysqlclient error: mysqlclient 1.3.13 or newer is required; you have 0.9.3

I've trawled the forums but cannot find an answer or even any documentation on this. Trying to re-create a site like www.testandtrack.io
On running the command:
python manage.py inspectdb
I get the error:
mysqlclient 1.3.13 or newer is required; you have 0.9.3
I have tried all the suggested fixes including:
-upgrading pip
-installing a different wheel (32 bit instead of 64), namely mysqlclient-1.4.2-cp37-cp37m-win32.whl with the command pip install mysqlclient-1.4.2-cp37-cp37m-win32.whl (this works fine without an error but doesn't do the job required!)
My objective is to simply connect a legacy mysql database (running inside of XAMPP and myphpadmin) to Django. I've followed the documentation which misses out the need to install mysqlclient, and have got stuck at this point.
I guess your project uses pymysql instead of mysqlclient.
You can try to search the following code snippet in your project. If you find it, please try the following methods to fix this problem:
import pymysql
pymysql.install_as_MySQLdb()
Insert a line of code between these two to make it look like this:
import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()
Then try to start your project.
Why do I know you are using pymysql? Because 0.9.3 is just the latest version of pymysql.
Why use pymysql instead of mysqlclient for the project? Because it is easier to install. pymysql does not depend on system libraries, while mysqlclient relies on a series of system libraries such as libmysqlclient-dev.
Why is mysqlclient difficult to install and Django still uses it by default? Because mysqlclient is faster and performs better. So if your project has high performance requirements, I suggest you remove the compatible code above and install mysqlclient in your project. If you need help during the installation of mysqlclient, please refer to this link: How to install Python MySQLdb module using pip?, and ensure libssl-dev has been installed before pip install mysqlclient.
This is how I fixed it.
Go to your django/db/backends/mysql installation dir.
Check your path in the error message.
I'm using pipenv so my path is:
/home/username/.local/share/virtualenvs/project-env/lib/python3.7/site-packages/django/db/backends/mysql
If you use traditional env your path would be:
<env_directory_name>/Lib/site-packages/django/db/base.py
Open file base.py and search for:
version = Database.version_info
Put a pass inside if and comment line:
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required;
you have %s.' % Database.version)
Like this.
if version < (1, 3, 13):
pass
'''
raise ImproperlyConfigured(
'mysqlclient 1.3.13 or newer is required; you have %s.'
% Database.__version__
)
'''
Save, close this file and open operations.py.
Search for:
query = query.decode(errors='replace')
and change decode to encode
query = query.encode(errors='replace')
Now, try to run the server.
#edit
Until this answer, I found no other way to solve it. Today there are better ways to deal with this problem. This answer has a better approach.
I have had the same issue as lower version of mysqlclient was installed due to pymysql.
OS: Linux Mint 19.1
Python: 3.6.8
Django: 2.2.2
Uninstall mysqlclient: pip3 uninstall mysqlclient
Uninstall pymysql: pip3 uninstall pymysql
Install mysqlclient: pip3 install mysqlclient
this problem occurs when you create Django project in pycharm by default settings.
It's caused by the default version of django is 2.2.6, so just downgrade the django version to 2.1.7, and error in the terminal is gone.
pip install Django==2.1.7
that's all!
Instead of edit internal configuration, try to upgrade the version of mysqlclient
pip3 install -U mysqlclient
The following solution works in Django 3.2.3 to get rid of the 'mysqlclient 1.3.13 or newer is required; you have 0.9.3' problem:
1) pip uninstall mysqlclient # remove old version
2) pip install mysqlclient==1.3.13
3) comment or remove the old workaround in __init__.py of the main app.
# workaround django.core.exceptions.ImproperlyConfigured:
#Error loading MySQLdb module.
#Did you install mysqlclient?
#import pymysql
#pymysql.install_as_MySQLdb()
Install wheel:
pip install wheel
Download file that you want from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
Move to your Downloads directory (I guess it'll be cd Downloads)
Install downloaded file with: pip install <file name>
WARNING!! You CANT edit name of downloaded .whl file. It contains some information what is required to install.
It worked fine with me just open settings.py and include
import pymysql
pymysql.version_info = (1, 4, 6, 'final', 0)
pymysql.install_as_MySQLdb()
I had a similar issue, I was getting
"django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 1.3.12."
So I went to the C:\Users\username\Envs\env\Lib\site-packages\django\db\backends\mysql, opened base.py and changed that line...
if version < (1, 3, 13):
to...
if version < (1, 3, 10):
which is a version lesser than mine and it worked.
If it's not critical for you, as a variant, just downgrade your django framework from 2.2.2(for example) to 2.1.
I was finding a solution for this issue from a long time. I was using Ubuntu 18.04 and found this solution to be useful for python version 3.7.5
Step 1. Install libpython3.7-dev via sudo apt-get install
> sudo apt-get install libpython3.7-dev
Step 2: Install mysqlclient
> python3 -m pip install mysqlclient==1.4.6
If you are working with Django on ubuntu, i will suggest you do the following to resolve the issue than editing django specific configuration files
run the following commands in the terminal
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
pip install mysqlclient
Maybe your Django project uses pymysql, instead of upgrading mysqlclient, just do
pip install pymysql -U
This works for me ! :D
There are the same issue on github. Solution that perfectly fits for me is here.
I just quote an author:
I first pip uninstall pymysql (as it seems it doesn't work anymore)
Then I've used pip install mysqlclient
Last, I checked all my "pymysql" imports and deleted them.
Be sure to go and hit a like button on the comment in the link
Go to your virtual environment directory like mine:
C:\Users\user\.virtualenvs\RPA-Orchestrator-Backend-GwIL98hN\Lib\site-packages\django\db\backends\mysql\base.py
Here you might edit one line to avoid your error in the base.py file,
version = Database.version_info
if version < (0, 9, 3):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
Then your problem might solve.

MySQL for Pycharm

I'm creating a web application on pycharm using flask framework. i have to create database. i dont have any sql database in system and have no idea how it should be done. i want to know how it can done?
should i download MySQL first and then create db files in pycharm?
please guide me.
I have a suggestion,if you have install MySQL database,you follow this,open pycharm and click File->Settings->Project->Project Interpreter,then select your Python interpreter and click install button (the little green plus sign),input "MySQL-Python" and click the button "install package",you will install MySQL-Python successfully.If you have not install MySQL database,you need install MySQL database first.
Or you may go with.
From Windows Command Prompt / Linux Shell
install using wheel
pip install wheel
Download 32 or 64 Bit version from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
64-Bit
pip install MySQL_python-1.2.5-cp27-none-win_amd64.whl
32-Bit
pip install MySQL_python-1.2.5-cp27-none-win32.whl
Using Anaconda2:
Open a Command Prompt
$ conda install mysql-python
Press y to proceed with installation

Installing MySQLDB for python 2.7 using pip on Windows 7 64bit

I have spent hours trying multiple approaches to install MYSQLDB module for python, and no success.
My python version: 2.7.6
Django - 1.10.3
OS: Windows 7 64-bit
MySQL connector - MySQL Connector C 6.0.2
Currently I have an error in my project, namely:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I have tried to install mysqldb running the following command:
pip install mysql-python
It ran successfully, but the error still persisted. Then I tried to run
pip install MySQL-python
and I am getting Cannot open include file config-win.h.
I came across this post, but I don't understand the idea of the answer, specifically, I can't figure out where I should look for the mentioned files site.cfg and setup_windows.py. There are no such files in C:\Program Files\MySQL\MySQL Connector C 6.0.2\include
Finally, I tried to install MySQLDb using wheels running
pip install mysqlclient-1.3.9-cp27-cp27m-win_amd64.whl command, I end up with
mysqlclient-1.3.9-cp27-cp27m-win_amd64.whl is not a supported wheel on this platform error.
I have lost my hope. Help please !!!
Try to install 32 bit version mysqlclient-1.3.9-cp27-cp27m-win32.whl
If it doesn't work try to install it from (where you can find compiled windows libraries):
http://www.lfd.uci.edu/~gohlke/pythonlibs/

Can't use npm_modules after installation

I'm starting a project where im going to use AngularJS, NodeJS and MySQL. This is my first real web application, and it's also the first time im using npm.
I've installed Node from their official website, and when i write npm install the node_modules comes to the project directory.
The problem occurs if I try to use any of the installed npm_modules. I tried to download mysql, and the installation worked, but when i type mysql -p i get: "bash: mysql: command not found"
I've also tried to install it with npm install mysql -g, but it still doesn't work.
If it means anything my $PATH is /usr/local/git/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/local/bin
The mysql npm package contains just the nodejs client library for mysql. You need to install the mysql server separately using the appropriate method for your OS.
it looks like you have not installed mysql on your system.
install mysql server using the following command
sudo apt-get install mysql-server

Installing Pygame without whl files [duplicate]

Currently unable to install Pygame via pip:
pip install pygame
Getting this message:
Concerned by it being termed an EOF error, is this an error in the module itself?
There's dev versions available as of now. Get them via
pip install pygame==2.0.0.dev6
Pygame is not compatible with Python 3.8 at the moment. I would recommend you to downgrade back to 3.7 and installing with pip there.
pip is doesn't have pygame up.
But there is a alternative that worked for me. https://www.pygame.org/wiki/CompileWindows
Read and follow the steps correctly and it should install.
you also need to update your code to pygame 2.0.0 code because it's only for 3.8
BTW you have to follow the SDL2 instructions since pygame 2.0.0 uses that.
the above commands worked for me today 3-15-20 with Python-3-8-0 on Linux Mint 19
to get IDLE to recognize pygame.
sudo pip3 install pygame==2.0.0.dev6
I also had to update pip first with
sudo pip3 install --upgrade pip
Pygame requires visual studio C++ build tools to install. Ensure you have these downloaded from here.
Open power shell window and make sure your internet is on
Then type the following command
pip install pygame
It will automatically download it for you and also install it
Again make sure your internet is on
I have python 3.8.2 and it worked on my pc