Wednesday, October 8, 2014

Django using Python3.3 on Debian wheezy - how to

Debian 7 comes with python 2.7.3, and python 3.2.3

To use python2.7.3, we use the command "python" and to use python3.2.3 we use "python3"

The goal is we want to use python3.3.x. Why? you asked. That's a very good question!
The reason is because I want to use MySQL as the database and MySQL Connector Python 2.0.1 only supports Debian 6. 

I have to use the platform independent version of MySQL Connector Python instead of the Debian version.

So, first I have to install Python3.3 from source and this page shows me how.

I am going to tell you how anyway.

sudo apt-get install build-essential
sudo apt-get install libsqlite3-dev
sudo apt-get install sqlite3
sudo apt-get install bzip2 libbz2-dev

Cool! then I download and compile Python3.3

cd /home/me/downloads
tar xJf ./Python-3.3.5.tar.xz
cd Python-3.3.5
./configure --prefix=/opt/python3.3
make && sudo make install

I prefer to use alias for Python3.3 and I called it "py"

echo 'alias py="/opt/python3.3/bin/python3.3"' >> .bashrc

That's it! I now have Python3.3 and the next step is to install Django 1.7. But before we do that, we must first install "distribute" and here how I did it. "Distribute" can be found on this page

cd /home/me/downloads
cd distribute-0.7.3
py install

Now we have distribute package which is what we need to install Django 1.7. Without this package, it will throw an ImportError: "No module name setuptools"
Get the latest release of Django 1.7 here

cd /home/me/downloads
tar -zxvf Django-1.7.tar.gz
cd Django-1.7
py install

Great! I now have Django 1.7 installed. NOTE: when using, you must call it using "py" instead of just "" as mentioned in the Django tutorial.
Find out where "" was installed here:


Last step is to install MySQL Connector Python, well, because I want to use MySQL. That's the reason why this post is created.
Download MySQL Connector Python here

cd /home/me/downloads
tar -zxvf mysql-connector-python-2.0.1.tar.gz
cd mysql-connector-python-2.0.1
py install

Now you can start a new project by calling

py /usr/local/bin/ startproject mysite

To use MySQL Connector Python, edit your as below

    'default': {
        'ENGINE'  : 'mysql.connector.django',
        'NAME'    : 'mysite',
        'USER'    : 'root',
        'PASSWORD': 'IShallNotUseRoot',
        'HOST'    : '',
        'PORT'    : '3306'

REMEMBER: Use "py" (in my case) for all the call, such as py runserver.
Hope this helps you!

No comments: