Build a Blog App using Flask, Angular and MySql using Ubuntu (Part 1) - Installing Python

Subscribe to my newsletter and never miss my upcoming articles

In this tutorial, we will be setting up the local development environment for our Project. We will be using Python 3.6 and Ubuntu 16.04 for this project to setup Flask. (You can use any OS or Python version of your choice).

Installing Python 3.6

$ sudo apt-get install software-properties-common python-software-properties
$ sudo add-apt-repository ppa:jonathonf/python-3.6
$ sudo apt-get update

Finally install python 3.6

$ sudo apt-get install python3.6

Setting python3.6 as default

To make python3 use the new installed python 3.6 instead of the default 3.5 release, run following 2 commands:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5.1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2

Finally switch between the two python versions for python3 via command:

sudo update-alternatives --config python3

Select Python3.6 version and Press Enter

Now check using

$ python3 -V

gnome-terminal won't launch after step 3, a workaround is running following commands to recreate the symlink:

sudo rm /usr/bin/python3
sudo ln -s python3.5 /usr/bin/python3

Installing PIP

$ sudo apt-get install python3-pip

Using python in project

$ mkdir mypythonproject
$ cd mypythonproject

Installing virtual environment for project

To install virtualenv via pip $ pip3 install virtualenv

Note that virtualenv installs to the python3 directory $ which virtualenv

If virtualenv is not found

$ sudo /usr/bin/easy_install virtualenv

Setting up virtualenv for the project

$ virtualenv -p python3.6 venv --no-site-packages

Activate the virtual environment

$ source venv/bin/activate

Install any pip packages

$ pip3 install package_name

Show all installed pip packages

$ pip freeze > requirements.txt

To install the packages in requirements.txt

$ pip install -r requirements.txt

Deactivating Virtualenv

$ deactivate

Deleting your virtual environment

$ rm -rf /home

Check Python Installation

$ python

In the Shell

x = ('a', 1, False)

No Comments Yet