Solved

MySQL-python installation error

Posted on 2014-11-08
8
308 Views
Last Modified: 2014-11-13
I am ready to install Django.  MY-SQL-Python is a prerequisit for mySQL connection to Python.  I ran
pip install mysql-python

Open in new window


and ran into the following error (in fact there were other errors before this last one, but found that the version of MS Visual C++ was not compatible with Python. Problem was corrected after installing MS Visual C++ 10)

Attached is the pip.log.  What should I do to fix this error?
pip.log
0
Comment
Question by:cpeters5
  • 4
  • 4
8 Comments
 
LVL 25

Expert Comment

by:clockwatcher
ID: 40430310
MySQL-python doesn't have a python 3 version available.  So don't think you are going to be able to get it installed under python 3 which appears to be what you are running.
0
 

Author Comment

by:cpeters5
ID: 40430458
clockwatcher,  
Yes, I am using python 3.3.  What are other choices for mysql-python subsitute?
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 40430846
I don't use django but a quick google and it appears that the mysql-connector (http://dev.mysql.com/downloads/connector/python/) which does have a python 3 version available will work with it:

  http://saltnlight5.blogspot.com/2014/09/django-with-python-3-and-mysql-database.html
0
 

Author Comment

by:cpeters5
ID: 40431260
Thanks clockwatcher.  That is the same version I used in the installation.  I saw that it supported python v.3.  But thought there might be some undocumented problem.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:cpeters5
ID: 40431281
clockwatcher and all,
What DBI and web modules  do you prefer for web-based/database application development in Python?
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 40431298
I prefer pyramid (http://www.pylonsproject.org/) for web development and SQLAlchemy (http://www.sqlalchemy.org/)  for relational databases.  

But we should be able to get django and the mysql-connector working.  I'll do a quick python 3.3 install later this morning and see how it goes.
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 40431440
Went ahead and found a few minutes to try it out and it works fine.  Here's a walk-through from start to finish to install django under python 3.3 in a virtual environment.  I always use virtualenv for my stuff and strive to keep my base python install as clean as possible.  If you don't care about that, you can ignore the virtual environment stuff.

Installed python 3.3 (64bit)

Installed setuptools (invoke powershell and then):
  PS C:\Users> (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | \python33\python

Install pip:
  \python33\scripts\easy_install pip

Install Python For Windows Extension/pywin32 (http://sourceforge.net/projects/pywin32) -- may not be 100% necessary but I always install this on windows.  Used to be necessary for virtualenv to work.  May not be any longer but it's a good library to have on windows anyway.

Install virtualenv:
   \python33\scripts\pip install virtualenv

Create a virtual environment for the django development:
   \python33\scripts\virtualenv mydjangoapp

Change directory to the newly created virtualenv:
   cd mydjangoapp

Activate the virtualenv:
   .\scripts\activate

Install django (in the virtual environment):
   pip install django

Install the mysql-connector (in the virtenv):
   pip install mysql-connector-python --allow-external mysql-connector-python

Create a django site:
   django-admin startproject mysite

Update mysite\mysite\settings.py (see http://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html for mysql-connector settings):
   'ENGINE': 'mysql.connector.django',
   'HOST':  'my.mysql.server.ip',
   'NAME': 'mydjango_db',
   'USER': 'mydjango_db_user',
   'PASSWORD': 'mydjango_db_password',
   'OPTIONS': { 'autocommit': True, }

MySQL setup:
   mysql -u root -p
   create database mydjango_db;
   create user mydjango_db_user identified by 'mydjango_db_password';
   grant all on mydjango_db.* to mydjango_db_user;
   update db set host='%' where db='mydjango_db';

Create the database (back in the virtualenv):
   python manage.py migrate

Start the server:
   python manage.py runserver

Open in new window

Everything worked fine.  I'm guessing the problem that you may have run into was that you were trying to use the MySQLDb django engine.  You need to make sure that you're using the engine appropriate to the connector that you're using.  Under python 3, you need to use the mysql-connector and the engine for that is mysql.connector.django (http://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html).  So you need to make sure you update the ENGINE setting in the settings.py file.
0
 

Author Closing Comment

by:cpeters5
ID: 40440971
clockwatcher,
Thank you for the clear instruction.  I was out of the loop for a few days.  Just tried your approach and able to install django in virtual env without error!  I will close this question but will continue to post new questions as I learn the art of web dev in python!  
pax
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now