Chase Roberts
Chase Roberts

Reputation: 9376

How to install MySQLdb with python 3.2

I'm trying to connect to mySQL with python. From what I understand you need to have MySQLdb which is some python connector module. My first problem was not having the right version of the mySQLdb. It can be found here. Then I am supposed to open a command line window and navigate to the path of the file I just downloaded (after unzipping) and typepython setup.py build This then gave me an error saying that I needed to downloaded setup tools. Setup tools apparently was discontinued after python 2.6 or 7. Now we are supposed to use distribute, which I found here, as a replacement. I did that and now when I try to make my build call It spits out

Traceback (most recent call last):
  File "setup.py", line 13, in <module>
    from setup_windows import get_config
  File "C:\Program Files\MySQL\MySQL-python-1.2.3\setup_windows.py", line 46
    print """You shouldn't be running this directly; it is used by setip.py."""

Syntax Error: invalid syntax

I need someone to hold my hand and walk me through how to get this setup. I've spent 6 hours on google trying to figure it out. (I read in more than one place that it is a difficult install but very worth it. I hope they're right.)

Upvotes: 4

Views: 14067

Answers (3)

user3330242
user3330242

Reputation: 41

Please note that you have to have curl installed. You can grab it from here.
Assuming python.exe command starts python3 on your machine.

Steps:

  1. Download distribute_setup.py from python-distribute.org/distribute_setup.py‎ to upgrade setuptools.
  2. Execute the following command to upgrade setuptools for your local python3:

    python.exe distribute_setup.py

  3. Download and install the pymysql driver:

    curl -L https://github.com/PyMySQL/PyMySQL/tarball/pymysql-0.6 | tar xz
    cd PyMySQL-PyMySQL-7c86923/
    sudo python3 setup.py install

  4. Download and install MySQLdb driver for python3

    git clone https://github.com/davispuh/MySQL-for-Python-3.git
    cd MySQL-for-Python-3/
    python3 setup.py install

  5. To check open python interpreter via python.exe command and execute:

    import pymysql
    import MySQLdb

If everything went ok - then both lines should not fail.

Upvotes: 4

Zamphatta
Zamphatta

Reputation: 4714

I couldn't get MySQLdb to work with Python 3 either, so I installed the MySQL/Connector module. It's been workin' like a charm & it was a simple install. I was a complete Python newbie at the time, so unless I'm a genius then it's pretty easy to install for anyone.

Upvotes: 1

Chase Roberts
Chase Roberts

Reputation: 9376

After further googling I don't think that using mysqldb or whatever is the best solution. I found this page: http://wiki.python.org/moin/MySQL I decided to give the mysql connector/python a try. It seems pretty straightforward with no crazy installs.

Upvotes: 0

Related Questions