Environment

MySQL

Python3 - Django - MySQL

Often times, the hardest part about a project is getting started. This section will include a description of how we set up our environment so that we were able to begin our project. Hopefully it will be useful to anyone looking to begin a similar project.

Linux

We decided to develop the application in linux because it seemed like most of the resources we were accessing regarding Django, Python3, and MySQL referenced linux commands more often than Windows. We chose Ubuntu as our distribution because we each already had it installed on our machines. Tutorials for installing Ubuntu are excellent and readily available. We chose to dual boot our windows operating systems with Ubuntu, which this tutorial describes how to do.

Python 3

Depending on the Linux distribution that you install, Python3 might already be installed. Try running python in a terminal to see what version is installed. If it's not installed, type 
sudo apt-get -y install python3 
at the command line and Python3 should be installed. Now you can run Python3 by typing python3 at the terminal.

Django

Django has a good set of instructions for installing their framework, the only caveat to observe is to make sure that when you run any 'python' commands you substitute 'python' with whatever version of python that you want to use. In our case, we found it easiest to manually install Django. When it came to the 4th step, we changed the command to
sudo python3 setup.py install
in order to make sure that Django was installed on Python 3. To make sure that it has been installed correctly, start the Python 3 command line and type in
import django
If the command line doesn't complain, then congratulations, you've officially installed Django!


MySQL

Unfortunately, Python3 and MySQL currently don't play nice together. This means that we have to install a third party application in order to use a MySQL database with Django. Quick Google searches turned up several options, the two most prominent of which were CyMySQL and PyMySQL. Ultimately we decided to go with PyMySQL because we were able to find more resources about the process of integrating Django with MySQL using this tool. A special thanks to this Stack Overflow response, which showed how easy it was to use PyMySQL.

MySQL

If you're like one of the members of our group, you don't yet have MySQL installed on your system. Following these steps might not be the most efficient way to install MySQL, but it will definitely get the job done.
  1. Open 'System Settings' and select 'Software Sources' under the 'System' group at the bottom of the page.
  2. Select the 'Other Software' tab and then check the 'Canonical Partners' box.
  3. Now in a terminal, type: sudo apt-get update
  4. Following that command, type: sudo apt-get install synaptic
  5. After the installation completes, open synaptic.
  6. Type "mysql" in the quick filter bar to find mysql packages. Select the box next to 'mysql-server-core-5.5' or whatever the most recent version is and install all of the dependent packages.
MySQL should now be installed, to check, you can enter the following command in a terminal:
mysql -V
The terminal should output the version information for MySQL.

setuptools

Installing setuptools, a necessary component of PyMySQL, is relatively simple and can even be done in one line! Here is the command to install it:
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | sudo python3
If that command doesn't work, don't blame us, blame this website where we got our information.

PyMySQL

Special thanks are again due to this Stack Overflow response that described how to use PyMySQL to integrate Python3 and Django.

We couldn't figure out how to make pip work with Python3, so we used the manual installation method for installing PyMySQL. Here is a walk through of the process:

  1. Download the .zip folder for PyMySQL from gitHub.
  2. Unzip the contents, then navigate to the directory.
  3. Do this command: python3 setup.py install, or follow the instructions in the readme.rst to install.
  4. During the installation process, some error messages may appear, despite this, the installation may still be successful, try starting python3 and importing pymysql to make sure that it worked.

Eclipse

In order to use Python plugins with Eclipse, you'll need to be on the latest version. Arik found an excellent tutorial to install the most recent version of Eclipse on Ubuntu. Follow these steps and you should be golden.

PyDev

PyDev is a plugin for Eclipse that allows easy development of Python projects. It's super easy to install with the Eclipse software manager. In Eclipse, click on the "Help" menu at the top, then select "Install New Software..." In the "Work with:" field, copy and paste this web address: http://pydev.org/updates then check the PyDev checkbox and select "Next". Continue to make appropriate choices until PyDev is installed. PyDev gives you lots of useful commands for automatically building Django content and running tests.




No comments:

Post a Comment