How to access MySQL from python - mysql

I've always used Xampp for db/ server purposes. I'm trying to use the same with my Python project but cannot seem to get it to work.
Error from Python Shell
import MySQLdb
ImportError: No module named 'MySQLdb'
I've been all around but nothing seems to work. I'm on windows 7, Python 3.3.
Please someone advise. Links that would resolve this quick will be greatly appreciated.
Update:
Please note that it seems MySQL-python does not support python3

From this discussion : https://groups.google.com/forum/#!topic/django-developers/8r_RVmUe5ys
Here is some connectors that can be used for mysql in Python 3.x:
https://github.com/davispuh/MySQL-for-Python-3 / https://github.com/clelland/MySQL-for-Python-3
http://www.pymysql.org/
https://github.com/farcepest/moist
https://pypi.python.org/pypi/mysql-connector-python/1.0.9

pip install MySQL-python
Run this in your Windows console or Linux terminal, and this problem should disappear.

Related

cx_Freeze does not seem to import nor install using pip

When I try to import CX_Freeze I get this error:
But I tried to compile a pygame script I made anyways and I got this error:
If you can help me that would be great.
Thank you
try the below command to see you installed packages:
pip list
If you do not see cx_Freeze displayed in the list try to install by this command:
pip install --upgrade cx_Freeze
As the error states, you need to install or update Microsoft Visual C++ to 14.0 or greater. If you don't want to, try other modules such as py2exe
See also:
https://www.pygame.org/wiki/Pygame2exe

Unable to use LocateOnScreen function on Pyautogui (Python 3.9)

Here is my code:
import pyautogui
cord = pyautogui.locateOnScreen('chrome.png')
pyautogui.doubleClick(cord)'
However, I got this error:
I installed Pillow and imported PIL
I also installed opencv and numpy.
Through some research I realised it could be some site-package issues/ environment issues. I uninstalled and reinstalled python and updated the PATH.
please help I am at my wits end.
Known problem - i had it too. Maybe downgrade to 3.8 OR even 3.7.
I had to downgrade to 3.7 because a module in pyautoGUI made my script crash.

Cannot connect to a mysql:// instance with SQLAlchemy from my Mac

I'm trying to connect to a mySQL database through SQLAlchemy and I can't get it to work for the life of me. Here's the code I'm running and the error I'm getting.
import pandas as pd
import sqlalchemy as sql
import urllib.parse
user = 'user'
pswd = urllib.parse.quote_plus('password')
connect_string = 'mysql://{}:{}#localhost:8018/test'.format(user, pswd)
sql_engine = sql.create_engine(connect_string)
>>> ModuleNotFoundError: No module named 'MySQLdb'
After seeing this, I've tried numerous different ways of installing 'MySQLdb' ( including the obvious 'pip3 install mysqlclient') and when I run that in my terminal, I get the following.
>>> ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
I know this question has been posted here before but I've spent 2 hours now trying to figure this out with the advice on those other questions and nothing is working. Can anyone help? Below is a picture of the full error I'm getting when I try and install "mysqlclient"
According to
https://pypi.org/project/mysqlclient/#files
mysqlclient only offers pre-compiled wheel files for Windows machines running 64-bit Python 3.6, 3.7, and 3.8. All other configurations require that it be installed from source, and that can be ... complicated.
You may want to try installing PyMySQL instead, and use a connection URI of the form
mysql+pymysql://<username>:<password>#<host>/<dbname>[?<options>]
SQLAlchemy is a high-level ORM. To connect to backends it needs Python DB API driver(s). You can install SQLAlchemy with a MySQL driver using
pip install -U 'SQLAlchemy[mysql]'
See the list of extra drivers available for such installation.
Most drivers have parts written in C/C++ and thus require compilation. You need to install MySQL-related libraries to compile mysqlclient. See https://stackoverflow.com/search?q=%5Bpip%5D+install+%5Bmysql%5D+%22mysql_config%22+not+found
There are a few pure-Python drivers. They're easier to install. PyMySQL is one such driver. To install it along with SQLAlchemy:
pip install -U 'SQLAlchemy[pymysql]'

Error in importing MySQL connector in Python 3.5

I am getting ImportError: No module named 'mysql' while I do the following...
>>> import mysql.connector
MySQL is installed and am on Python 3.5. I can't figure out. The above command is running fine in Python 2.7.
Unfortunately there is no mysql-connector available for python3.5.
So, you can use pymysql module which is a replacement for mysql-connector package
pip install pymysql
import pymysql
Connection = pymysql.connect(host='hostname', user='username', password='password',
db='database',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor )
ExecuteQuery(Connection)
Connection.close()
For me (OS X 10.11.4, Python 3.5.1), the mysql-connector-package installed itself (by default) into Python 2.7 that was also on my system. I copied the mysql package directory from:
/Library/Python/2.7/site-packages/mysql to /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mysql. Everything works. According to http://dev.mysql.com/doc/connector-python/en/connector-python-versions.html the connector package supports Python 3.3+.
Your specific installation path for the module may be different, but you can easily check this from the REPL using the sys.path:
https://leemendelowitz.github.io/blog/how-does-python-find-packages.html
As we need to be connecting MySQl with Python, the Python command assumes that the connector is enabled. So we need to follow the steps below:
open MySQL Installer;
go to "Custom settings";
go to "Connectors";
choose the connector\Python and version based on the one you are using;
add it;
use import mysql.connector.
It should run, in my case it did!
From Can't run MySql Utilities:
MYSQL Utilities assumes that the MySQL Connector for Python has been installed. If you install it (http://dev.mysql.com/downloads/connector/python/), MySQL Utilities should run OK.
I think this link may help you to solve your problem.

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.