0

Recently I installed Python 3.4.3 in my environment (Windows 8.1) and tried to deploy a simple Django server. When I runned the command python manage.py runserver but the following exceptions appeared:

Unhandled exception in thread started by .wrapper at 0x031B5D68>

I believe this exception happened due some error or misconception when I tried to install mysql-python. I changed the DATABASE config in settings.py from "django.db.backends.mysql" to "django.db.backends.sqlite3" and runned pretty well. The configs that I tried are the following:

# Defective configuration
DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'test',
    'USER': 'user',
    'PASSWORD': 'doideira',
    'HOST': '127.0.0.1',
    'PORT': '3306',
  } 
}

But using SQLite works:

# With SQLite 3 works
DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.sqlite3',
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  }
}

I am experiencing some troubles and any advice would be appreciated. I would like to know why this is happening and how can I workaround it.

Further info:

  • Mysql version is 5.6.4
  • Mysql Python version is 1.2.5
  • Python version is 1.2.5
  • Windows 8.1
  • Django version is 1.8.1

The full log error can be seen here.

Update Saturday 16, May 2015:

I came up with an simple solution: downgrade Python from 3.x to 2.7.x. I explain the steps below as the answer of my question. I also found this answer very useful, but now that I'm using Python 2.7 everything is ok.

I also found this article that answers the question "Should I use Python 2 or Python 3 for my development activity" and that was what made me to decide whether keep with Python3 or Python2. Since Python3 hasn't a strong library support, I will wait a little more until update it.

2
  • 1
    I believe Mysql Python is not compatible with python 3.x yet. Check documentation here: pypi.python.org/pypi/MySQL-python/1.2.5 Commented May 14, 2015 at 5:32
  • That's right @nikhiln. It seems that Python 3.x is not supported yet. I just need to downgrade Python a little bit and run some scripts. Thanks for the hint. Commented May 16, 2015 at 20:18

2 Answers 2

1

For Python 3 we need to install mysqlclient and PyMySQL

Sign up to request clarification or add additional context in comments.

Comments

1

Eureka! I figured out the answer guys.

As @nikhiln mentioned in the comments, mysql-python is not supported yet for Python 3.x:

MySQL-3.23 through 5.5 and Python-2.4 through 2.7 are currently supported. Python-3.0 will be supported in a future release. PyPy is supported. mysql-python 1.2.5

To work around it, I downgraded my Python from 3.4 to 2.7.9, and installed the Microsoft Visual C++ Compiler for Python 2.7 and Microsoft Visual C++ 2008 SP1 Redistributable Package (x64) to properly run it.

Then I installed the mysql-python client using a .whl file from Christoph Gohlke`s Unofficial Windows Binaries for Python Extension Packages. I did as following (assuming C++ 2008, Compiler for Python and Pip are already installed):

  1. pip install wheel to install the wheel program. With it you are able to compile .whl files.
  2. Download the properly file MySQL_python‑1.2.5‑cp27‑none‑...
  3. Run the command pip install MySQL_python‑1.2.5‑cp27‑none‑...whl (the file you downloaded in the previous step).

And Voilà! mysql-python is running swiftly now! To check if everything is ok, just run import MySQLdb into Python shell.

>>> import MySQLdb

If no exception was raised, then the work is done.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.