Saturday, December 17, 2016

Guide - How to setup Django 1.10.4 with Python 3.4.3 x64 and MySQL 5.7 x64 - Windows10 x64

Hej all!

A small guide here on how to setup Django 1.10.4 with Python 3.4.3 and MySQL 5.7 and Windows 10.

I decided to make this guide after I lost several hours trying to get Django to work with MySQL, this was a hassle! not so much that's complex to setup but rather to find the right wheel file that would work with these versions. And the graceful moment where you find out and finally got things to work :).

I use Python 3.4 as there does not seem to be a working mysqlclient build with Python 3.5 at the moment although I have an idea and will try this later (For a next guide).

So let's get started,

1. Download MySQL Installer for windows (here) and install MySQL
  • After install, launch MySQL Workbench and create a new db schema and a db user with dbadmin rights
2. Download Python 3.4.3, take the file Windows x86-64 MSI installer from here and install

  • Select "custom install" and select  "add path environm. variables"
  • Once installed check your version in a win command line with , "Python --version"
  • Create a new Python virtual environment for your project

  • "cd" to the "SCRIPTS" folder created in your freshly created virtual environment folder and activate it. You should now see the name of your venv folder between parantheses in the front) to deactivate the environment enter "deactivate.bat" from the same location.

3. Install Django
  • Install django with command "pip install django" 

4. Now we need to install a compatible mysql python driver, this is in this case the "mysqlclient" Python package, but if you want this to be reliable you should :

 5. Now back to django, "cd" to your project directory and enter the following in a win command line
  • "django-admin startproject YourProjectname", this will create a new django web-project 
  • Go into the folder project and edit the file and make the following modifications to the DATABASES section in it,

'default': {
            'ENGINE': 'django.db.backends.mysql',
              'NAME': 'YOURDBNAME',
        'HOSTNAME': 'localhost',
            'USER': 'YOUR_USER_NAME',
                'OPTIONS': {
                                'autocommit': True,

                      • Save
                      • Now ready to create the needed database tables for the Django project, Enter : "python migrate" and you should see the message displayed below.

                      Project ready to code :)

                      No comments:

                      Post a Comment