I just want to be able to do a simple SELECT * FROM
query.
I found a Python MySQLdb
Package, but can\'t get it to install using the Windows
The problem is that the binary installers for Python packages are looking for a specific registry key, which does not exist if you are using the Anaconda installer.
To make matters worse, Anaconda doesn't provide database drivers in either their commercial or free repository.
So now you have two options
Recommended - get rid of Anaconda. Uninstall it. Install Python using the official Python installer for Windows. At this time, I would recommend the 2.7.x series for maximum compatibility. To make your vanilla installation the same as Anaconda, you can install the packages that are bundled with Anaconda separately.
The Laboratory for Fluorescence Dynamics at the University of California, Irvine maintains a repository of Python packages that are difficult to install on Windows. They have taken these packages and converted them into Windows installer binaries. So, simply download and double click to install. Just like the MySQL installer, these will also only work with the official Python installer; for the same reason.
The main packages you are probably after, you can start by installing the following:
It will take some time to download these, but they are all Windows installers so you just have to double click your way through them. Keep in mind the pre-requisites (indented entries above).
The other option is to trick the MySQL installer (and other Windows installers) into thinking the Anaconda installation is the official Python installation. You can do that by modifying the registry.
For Windows 7 64, create a file with the following:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath]
@="D:\\Python27\\"
Replace "D:\\Python27\\"
with the path to your Anaconda installation. Save the above file with a .reg
extension, then double click it to affect the changes to your registry. To do this might require administrator level access so the above might not work for your system.
I would highly recommend option #1 because it will ensure your system is setup to be most compatible with other Python libraries.
Anaconda comes with the conda installer, so use conda instead of pip. This works for all packages that are available for conda. There are MySQL packages available, you can select them from https://docs.continuum.io/anaconda/pkg-docs.
For pymysql you open up the command line, call 'conda install pymysql' and watch the magic unfold.
There is of course a trade-off (for the not-gurus like me at least): there are also packages that are not available for conda. tweepy is one of those. On the other hand, I did not manage to get sklearn installed using pip after uninstalling anaconda as suggested in the other answer.
[Edit:]I could install tweepy after searching on https://anaconda.org
[Edit, in response on question:] @scottlittle,you mean something like:
# -*- coding: utf-8 -*-
# imports
import pymysql
# open connection to the database
conn = pymysql.connect(host='localhost',
port=3306,
user='<your_user>',
passwd='<your_pwd>',
db='<your_db>',
charset='utf8')
cur = conn.cursor()
sql = "SELECT * FROM <your_favourite_table>"
cur.execute(sql)
# close connection to the database
cur.close()
conn.close( )