Posted by : at

Category : web-development   python   linux

Installing python3.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

$ 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)