Solved

MySQL-python installation error

Posted on 2014-11-08
8
313 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
any impressive Python code for a child? 3 116
Copy Files - Python 7 73
What is Python programming? 3 103
How to use pyenv 4 16
"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
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 while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

867 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

19 Experts available now in Live!

Get 1:1 Help Now