Thursday, February 8, 2018

Windows 10 Linux Subsystem, Flask with PyEnv Setup

The new Linux Ubuntu subsystem in Windows 10 is making quite a good impression, especially for developers. Also, using PyEnv with Virtual Environments allows greater flexibility in setting up development projects.

Linux Setup

Lets first prepare the Linux distribution for development:
    sudo apt-get update
    sudo apt-get upgrade

Development Baseline

Setup the development foundation:
    sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl libncursesw5-dev xz-utils tk-dev

Install PyEnv

Let's install the python version manager:
    curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash

Add the needed  environment variables:
    ~/.profile
    export PATH="/home/user/.pyenv/bin:$PATH"
    eval "${pyenv init -}"
    eval "${pyenv virtualenv-init - }"

Now update the running environment:
    source .profile

Create Project

Download the latest Python 3 stable available version:
    pyenv install 3.4.6

Create the virtual environment with corresponding Python version:
    pyenv virtualenv 3.6.4

Now install the rest of the tools needed!

Thursday, January 21, 2016

Ubuntu 15.10 64 bits with Node.js and Loopback

Well the time came to meet Node.js again and install the latest version 5.x as well as Loopback due to projects needs, here is the recipe:
  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install -y build-essential python python-software-properties g++ make git
  4. curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
  5. sudo apt-get install -y nodejs
Once all the previous has successfully installed, we install Loopback, and take our time for coffee, since it takes a while:
  1. sudo npm -g install strongloop

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!