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

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/

Related

AttributeError: 'NoneType' object has no attribute 'connect'

I am running Trac 1.2.2 on Python 2.7 with MariaDB on Ubuntu 18.04 and I have to move to Ubuntu 20.04 now. I know that Python 2.7 is not supported anymore, but I do still need to run it on my Ubuntu 20.04 server as I am running an older version of Trac which I can't upgrade right now because of plugins that are not working in the latest version...
So i migrated the MariaDB database, pip-installed MySQL-python with the help of this comment and I am now getting the following error in debugging-mode for Trac:
2021-03-18 10:16:31,836 Trac[main] ERROR: can't retrieve session: TimeoutError: Unable to get database connection within 0 seconds. (AttributeError: 'NoneType' object has no attribute 'connect')
Any idea of what I could have missed?
I was able to solve this issue by my own. The file from this comment is not properly working under Ubuntu 20.04
I copied the file my_config.h from an Ubuntu 18.04 installation to my Ubuntu 20.04 into /usr/include/mysql and then did pip install MySQL-python again, and now everything works as it should :-)

Deploying Django project on pythonanywhere: Error running WSGI application

I have a mysql database for my django project. Had also installed XAMPP for local development. While deploying I did. I think there's a problem with the python version of my pthonanywhere bash console. My project can support only python 3.7 because of the kiteconnect module that I am using.
I have installed kiteconnect, mysqlclient, and mysql connector (checked it with pip3 freeze too)
pa_autoconfigure_django.py --python = 3.7 <git-repo-url>
I set up my database and made the changes suggested in my settings.py file in DATABASE, (changed hostname, database name, passowrd, PORT:3306, etc). I am getting this error in logs:
Error running WSGI application
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
Please help me. This is a project I'm working on. Will be happy to provide further inputs too.
pa_autoconfigure_django creates a virtualenv using the requirements.txt file in your project. If you do not have mysqlclient in your requirements.txt file, then it will not be installed in the virtualenv.

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

Install PyAudio - Python 3.4

Unable to install pyaudio from the package python3-pyaudio_0.2.8-1_amd64.deb
with the following error message:
Dependency is not satisfiable: python3(<3.3)
I am on Ubuntu 14.04 where the default Python3 version is Python 3.4.
Is there a way to get this to work with Python 3.4 version or my only bet is to downgrade to Python 3.3 ?
If i did understand your question well, i recommend you check the following repository in github.
pyAudioAnalysis Installation
Use pip install pipwin on CMD after that use pipwin install pyaudio on ur program

ImportError: No module named 'MySQLdb' - django + mysql

This question concerns: django 1.5.1 with python 3.3 and mysql 5.6.12
Wanting to get Mysql running with Django. Had everything configured, even Database exists with user-pemissions. Got some error when trying syncdb:
ImportError: No module named 'MySQLdb'
There is obviously the Mysql-Lib for python missing. Downloaded the master-edition from petehunt/PyMySQL. Tried "python setup.py install" . Says:
ImportError: No module named 'constants'
Downloaded another version. A tarball from here. Run "python setup.py install". Seems to work, tried to run the syncdb command "python manage.py syncdb". Still:
ImportError: No module named 'MySQLdb'
Any suggestions what to do now? Thanks in advance.
mysqlclient is the recommended mysql driver for python 3
You can install it via pip:
pip install mysqlclient
Well I solve it. Downgraded to 2.7.x , so that i could use this. Seems to me there should exist a big red warning for using django with python 3.x and Windows 7.