Django Getting Started Part 3 about Python3 & MySQL Connector

* This article is an unsolved article.

Development environment

PC: MacOS X 10.9.4 Python3.4.1 Django1.6.6

Phenomenon that DB setting is not reflected

Previous article I thought that the project was created successfully, but I noticed that the database settings of ʻEclipse` below were not reflected. ..

スクリーンショット 2014-09-02 14.46.18.png

I synced with the database ($ python3 manage.py syncdb), but it is not reflected in the target MySQL database. When I check the description of the DB setting in setting.py, it is the setting of sqlite3. So I commented it out and wrote the settings for mySQL directly.

setting.py


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django_db',
        'USER':'db_user',
        'PASSWORD':'xxxxxxx',
        'HOST':'localhost',
        'PORT':'3306',
    }
}
#DATABASES = {
#    'default': {
#        'ENGINE': 'django.db.backends.sqlite3',
#        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#    }
#}

Frequent MySQL module errors

However, when I synced ($ python3 manage.py syncdb) again, the following error came to occur.

ImportError: No module named 'MySQLdb'

Apparently, I can't find the MySQL module. So I tried to install the MySQL module.

$ pip3 install mysql-python

However, this time the following error.

ImportError: No module named 'ConfigParser'

This time, I tried to install it below.

$ pip3 install mysql-connector-python --allow-external mysql-connector-python

This time, the installation itself seems to have worked. However, the error still continues.

ImportError: No module named 'MySQLdb'

Install MySQL-for-Python-3

I didn't give up, and the latest MySQL-for-Python-3 was on Github, so I tried installing it.

pip3 install --user https://github.com/davispuh/MySQL-for-Python-3/archive/1.0.tar.gz

The installation itself seems to have worked. But another error follows.

Library not loaded: libmysqlclient.18.dylib

So I made a symbolic link for libmysqlclient.18.dylib in / usr / lib, which would be in the MySQL library.

$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Supplementary information

After that, I read the Django Official Manual and found the following description.

Python 3 At the time of writing, the latest release of MySQLdb (1.2.4) doesn’t support Python 3. In order to use MySQL under Python 3, you’ll have to install an unofficial fork, such as MySQL-for-Python-3. This port is still in alpha. In particular, it doesn’t support binary data, making it impossible to use django.db.models.BinaryField.

Put simply,

Python3 At the time of writing, the latest release of MySQLdb (1.2.4) does not support Python 3. If you use MySQL, you should install an unofficial fork version like MySQL-for-Python-3. This port is still an alpha version, especially because it doesn't support binary data, so django.db.modules.BinaryField isn't available either.

Hmmm ~.

As a progress

Apparently, as far as I can check on the Web and the manual, it seems that MySQLdb does not support Python3 at this time (end of August 2014).

So how should we give up? Since I'm a beginner of Python, I can't get a sense of the release interval (how long I should wait for it to be supported).

  1. Change the DB (MySQL → other DB)
  2. Change the Python version (3.4 → 3.1)
  3. Stop studying Python / Django

By the way, I was addicted to Ruby on Rails a year or two ago around the MySQL connector.

After all, I feel that it is not a problem for Python beginners to poke their necks. I am disappointed, so please give me some advice and suggestions.

Recommended Posts

Django Getting Started Part 3 about Python3 & MySQL Connector
Getting Started with Python Django (1)
Django Getting Started: 4_MySQL Integration
Getting Started with Python Django (4)
Getting Started with Python Django (3)
Getting Started with Python Django (6)
Getting Started with Python Django (5)
Django 1.11 started with Python3.6
1.1 Getting Started with Python
Getting Started with Python
Django Getting Started Part 2 with eclipse Plugin (PyDev)
Getting Started with Python
Getting Started with Django 2
Getting Started with python3 # 2 Learn about types and variables
Getting Started with Python Functions
Django Getting Started: 2_ Project Creation
Django Getting Started: 3_Apache integration
Getting Started with Django with PyCharm
Python3 | Getting Started with numpy
Getting Started with Python responder v2
Getting Started with Python Web Applications
Getting Started with Python for PHPer-Classes
Getting Started with Python Basics of Python
Getting Started with Python Genetic Algorithms
Getting Started with Python for PHPer-Functions
Getting Started with Heroku-Viewing Hello World in Python Django with Raspberry PI 3
Getting Started with python3 # 1 Learn Basic Knowledge
Getting Started with Python Web Scraping Practice
Getting Started with Python for PHPer-Super Basics
Getting Started with Python Web Scraping Practice
Getting started with Dynamo from Python boto
Python Basic Memorandum Part 3-About Object Orientation-
Getting started with Python with 100 knocks on language processing
Build Python + django + nginx + MySQL environment using docekr
[Translation] Getting Started with Rust for Python Programmers
Getting rid of DICOM images in Python Part 2
Getting started with AWS IoT easily in Python
Materials to read when getting started with Python
[Cloud102] # 1 Get Started with Python (Part 1 Python First Steps)
Settings for getting started with MongoDB in python
About python slices
QGIS + Python Part 2
About python comprehension
Django begins part 1
Python Django Tutorial (5)
Python Django Tutorial (2)
About Python tqdm.
About python yield
About python, class
QGIS + Python Part 1
I started python
Django begins part 4
About python inheritance
Python Django Tutorial (8)
About python, range ()
Python Django Tutorial (6)
About python decorators
Python: Scraping Part 1
Django + MySQL settings
Python Django Tutorial (7)
About python reference