Wednesday, November 25, 2015

VirtualBox Guest: Ubuntu 15.10 Python Development Server

I am now using Ubuntu 15.10 and Python 3 as a professional developer. The development environment is located in a VirtualBox running Ubuntu 15.10 Server almost bare-bones, ONLY pre-installed with OpenSSH server.

Let's prepare the development environment with the latest Django 1.9 using Python 3.5, GIT and VirtualEnvWrapper. I recommend using MobaXtexm to login into your Vbox using SSH keys.

Update Ubuntu to the latest patches and security updates and improvements:
sudo apt-get update; sudo apt-get upgrade
sudo apt-get install build-essential python2.7 python2.7-dev python3.4 python3.4-dev python3.5 python3.5-dev
sudo apt-get install mysql-server mysql-client
sudo systemctl status mysql
sudo apt-get install apache2
sudo systemctl status apache2
sudo apt-get install python2.7-mysqldb python3.4-mysqldb python3.5-mysqldb libmysqlclient-dev
sudo apt-get install sqlite3 libsqlite3-dev libreadline6-dev libgdbm-dev
sudo apt-get install zip zlib1g-dev libbz2-dev
sudo apt-get install python-pip python3-pip
sudo apt-get install git virtualenv virtualenvwrapper
Add python alternatives for more flexibility:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
Make sure all is in it's place:
sudo apt-get update; sudo apt-get upgrade
Modify file .bashrc for VirtualEnv use:
vim ~/.bashrc
if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then
    export WORKON_HOME=$HOME/.virtualenvs
    source /usr/local/bin/virtualenvwrapper.sh
fi
source ~/.bashrc
Now let's create the working environment:
mkvirtualenv some-project-name
pip3 install Django==1.9
Make sure we are running the intended version, start a python 3.5 session, import django and check the version:
python3.5
>>> import django
>>> print(django.get_version())
1.9
Prepare to create the initial Django setup:
mkdir src; cd src
django-admin startproject some-project-name
cd some-project-name
python3.5 manage.py migrate
python manage.py runserver 0.0.0.0:8080
We point out browser to the needed site to check (Virtual Box was previously setup for port forwarding): http://127.0.0.1:8888
Finally we setup a basic Git repo:
cd some-project-name
git init
git config --global user.name 'Your Name'
git config --global user.email your.address@your.provider

Sunday, October 12, 2014

Ubuntu 14.04 Django 1.7 Development With VirtualEnvWrapper and Git

I am now using Ubuntu 14.04 and Python3 as a professional developer. Now I need to setup a development environment using the latest Django 1.7 and also use Git and VirtualEnvWrapper, here is how I did it:

Update Ubuntu to the latest, from the command line:
sudo apt-get update
sudo apt-get upgrade


Lets add Git for source code versioning:
sudo apt-get install git


Ubuntu 14.04 already comes with Python 3 pre-installed, so all we need is to add the pip3 command:
sudo apt-get install python3-pip


In order to work with python3 and pip3 more as if it were the default python, add the following to the .bash_aliases file and source the file to added these new aliases:
python='python3'
pip='pip3'


Now all we need is to add is a development sandbox:
sudo pip install virtualenv
sudo pip install virtualenvwrapper


Add the virtualenvwrapper settings to the .bashrc file and source the file to setup the environment for use:
# VirtualEvnWrapper settings:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/dev
source /usr/local/bin/virtualenvwrapper.sh


Let's create the working environment:
pip install Django==1.7


Finally we setup Git:
git config --global user.name 'Your Name'
git config --global user.email your.address@your.provider


One thing to notice, is that the current Django 1.7 driver for MySQL is not working: MySQLdb. Yet the python connector supports Django and works fairly well:
pip install --allow-all-external mysql-connector-python

DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django',
        'NAME': 'YourDatabaseName',
        'USER': 'YourUserName',
        'PASSWORD': 'YourPassword'
    }
}

Monday, May 7, 2012

Python for Android, Part 1

We are now in the stage where we will start our learning curve on Android, and first things first. We need to prepare our development platform.

My assumptions are the following:
So we begin by installing Java, in this case Open Java JDK. Please follow the next steps (taken from Ubuntu Community Documentation Java):
  1. On a terminal window add the following commands:
    sudo apt-get install openjdk-6-jre
    sudo apt-get install icedtea6-plugin
    sudo apt-get install openjdk-6-jdk

  2. Download and Install the Android Development Kit:
    Download the Android SDK Starter Package
    Instructions on Installing the SDK

  3. Untar, unzip, and install (this is the latest version to the date of this post):
    cd
    tar -xzvf android-sdk_r18-linux.tgz
    sudo mv android-sdk-linux/ /opt
    cd /opt
    sudo ln -s android /opt/android-sdk-linux
    sudo chown -R (your-user-id):(your-user-group-id) 
    *

    NOTE I recommend to install in /opt (which is what I did), yet you can do it where ever you may want.

  4. Now execute the installer:
    cd tools
    ./android

  5. Select Android 2.2 latest revision and the Android SDK download will begin!

This is it, now stay tuned for Part 2 coming soon!

Sunday, April 29, 2012

Learning Python

So far so good! I have now managed to create my 1st webapp following the HF Python book, and one neat feature to know (though I come from a Django background, is the use of the CGI debugger feature!

If your like me, learning the ins and outs of the Python foundation, this will allow you to get more information on the standard error, streamed at the browser, for debugging purposes (HF Python, page 248). Add the following two lines of code to your main webapp script and let Python take care of showing you the details of the errors it has found:



import cgitb
cgitb.enable()

So now we go on to Python for Android and I'm sure you will like these two links:

Friday, April 27, 2012

Python 3

I have now formally started the python 3 learning curve, and have to say that Head First Python is a must read for any beginner or mid-level. Stay tuned for news and highlights on this new phase!

Friday, September 5, 2008

Thank you

It's been a while since I come in and do some writing; any ways, I would like to thank the following person, who inspired me to create a blog and keep it going:

Sandeep Krishnamurthy, Ph.D.

Friday, April 11, 2008

InnoTek Share From Linux Host to Linux Guest

I am using Ubuntu 7.10 and have created an InnoTek Guest virtual machine with Ubuntu 6.10, this due to project constraints. And so I needed a way to share between both my machines in an easy and practical way, thus I followed the instructions I found at:


How do I automatically mount my shared folder


The short story is:


1) Create a virtual machine with Shared Folders


2) Install the InnoTek Guest Additions on the given guest machine

3) Check what is the "name" of the shared folder, in my case it was "share"


4) Start your virtual machine and login


5) From a terminal console, edit the /etc/modules file and add at the end of the file: vboxvfs, vboxadd



# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

lp
vboxvfs
vboxadd





6) Also modify the /etc/fstab file to mount the share



# /etc/fstab: static file system information.
#
#
proc /proc proc defaults 0 0

/dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/ /media/floppy0 auto rw,user,noauto 0 0
share /home/fbenavides/Share vboxsf defaults 0 0

Now, reboot and the share is working properly; otherwise, follow the previous link for more hints as to solve this issue.