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

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.

Related

Spyder not Detecting Pygame Module [duplicate]

I have following issue of installing pygame package.
In file included from src/_numericsurfarray.c:23:
src/pygame.h:106:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
^
1 error generated.
error: Setup script exited with error: command 'gcc' failed with exit status 1
System information
Mac OS-10.9.2
python version- Python 2.7.5 :: Anaconda 1.6.1 (x86_64)
Any suggestion will be greatly appreciate ? Thanks.
Here (OSX Mavericks) I got able to install this way:
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi
pip install https://bitbucket.org/pygame/pygame/get/default.tar.gz
("default" branch is on commit e3ae850 right now)
Source: https://bitbucket.org/pygame/pygame/issue/139/sdlh-not-found-even-thought-it-exists#comment-3822470
See this other StackOverflow question too: PyGame in a virtualenv on OS X with brew?
I had the same issue. I tried all versions of the answers to this question including variations of pip and pip3. Finally, the one that worked for me was:
sudo easy_install pygame
Note, however, that: (1) https://setuptools.readthedocs.io/en/latest/easy_install.html says that easy_install is deprecated and recommends using pip. (2) pygame is installed in the old standard python 2.7 folder rather than in the python 3.8.3 that I just installed -- though I was able to use it successfully in VSCode.
My system is also OSX10.9.2,and I also meet you problem,and I'm still try some;
Maybe this will be help for you:
there are some step:
1.Install [Quartz](https://xquartz.macosforge.org/landing/);
2.Install Xcode-Command-Line,
but you may cant install it by `xcode-select --install`,
so you can down from
https://developer.apple.com/downloads/index.action ;
I suggest you setup xcode,and this really solute my some problem;
3.`brew tap homebrew/headonly`
`brew install smpeg --HEAD`
`brew install sdl sdl_image sdl_mixer sdl_ttf portmidi`
4. `sudo pip install hg+http://bitbucket.org/pygame/pygame`;
if you clone this repo and try `python setup.py install`,you may meet some weird problem;
I have try install kivy which is base on pygame and I try lots of times,but just success install pygame one time.Then I uninstall it and also can't install it ;(
some refer:
http://jamesfriend.com.au/installing-pygame-python-mac-os-108-mountain-lion
http://juliaelman.com/blog/2013/04/02/installing-pygame-on-osx-mountain-lion/
=======update
Now I have install pygmae sucess,remeber you should install xcode,not only xcode-command-line!
I managed to install pygame on Mac OSX 10.14.4 using the following:
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi
sudo -H pip3.8 install pygame
This Work for me:
If you haven't installed Python/pip via homebrew (you're using the system-installed Python), you would likely need to run sudo pip3 install pygame.
Before running  pip3 install pygame, I had also installed Command Line Tools for XCode), as well as XQuartz, and the following homebrew packages: brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi.
If homebrew fails to install smpeg you might need to do the following:
brew tap homebrew/headonly
brew install --HEAD smpeg
Source: http://jamesfriend.com.au/installing-pygame-python-mac-os-108-mountain-lion

Failed building wheel for mysql-python

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

iGraph install error with Python Anywhere

I'm trying to run a web app (built with flask-wtforms and using iGraph) on Pythonanywhere. As igraph isn't part of the already inculded modules, I try and install it using the bash console, as such:
pip install --user python-igraph
How ever, what I get is:
Could not download and compile the C core of igraph.
It usually means (according to other people having the same issue on Stackoverflow) that I need to first install:
sudo apt-get install -y libigraph0-dev
Except, apt-get isn't available on Pythonanywhere, as far as I know.
Is there any workaround to install the iGraph module for Python 2.7 on Pythonanywhere?
python-igraph installed perfectly fine in my account. My guess is that you're facing a different issue to a missing library. Perhaps a network error or something like that.

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

libmysqlclient15-dev on macs?

Does OSX need an install of libmysqlclient15-dev? I'm trying to compile a gem that is failing and a lot of sources says to install "libmysqlclient15-dev" but I only see this for Linux, not OSX. Am I missing something here?
brew install mysql
fixed this for me
I know this is old, but google got me here. So let's say the solution in 2018 for python3 on OSX.
brew install mysql-client
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
pip install mysqlclient
I just had the same problem and only got a partial working solution.
Here are the steps I made to make it work:
brew install mysql-client
brew install mysql-connector-c
IF YOU HAVE ZSH:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
ELSE:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
Now for the installation itself:
LDFLAGS=-L< your openssl lib folder location > pip install mysqlclient==< version >
for example:
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient==1.3.12
If you are using the mysql dmg file to install mysql you will need to edit your ~/.bash_profile and include this:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
brew install mysql
then
arch -x86_64 gem install mysql2 -v 0.5.3 -- --srcdir=/usr/local/mysql/include
Afterwards I was able to run bundle install.
Copied from Bragadeesh Jegannathan's blog post
Yes you will need to install this. For example if you are trying to install the mysql gem you will need the headers for the mysql library. This is because some gems need to compile native extensions, so they need the header files for any 3rd party libraries that the extensions uses.
On Mac OS X I recommend using MacPorts to manage the installation of these libraries/headers.
Those instructions are for Debian type Linuxes. The closest thing to Debian for OS X is Fink. After getting that installed and set up, you can say fink install mysql-unified-dev to get essentially the same thing as asking for libmysqlclient15-dev on a Debian or Ubuntu type system.
Beware that Fink installs its packages in /sw, and not all build scripts know to look there for libraries and headers. You might have to give custom build options to get it to figure this out.
A path that may be more successful is to simply download the MySQL 5.0 package for Mac OS X. That should include the same development files as libmysqlclient15-dev, and as a bonus will put them in places more likely to be found by your gem.
(Why 5.0, by the way? Because that's what corresponds to ABI version 15, which your package apparently requires. Maybe it will in fact work with 5.1, or 5.4, or 6.0, but that would be a risk you'd have to decide to take on your own.)