Solved

MySQL-python installation error

Posted on 2014-11-08
8
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

 

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
 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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…

695 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