Thursday, January 31, 2019

Python - install matplotlib - python3 with tkinter in Ubuntu


matplotlib

Step 1: Install matplotlib
Step 2: Install tkinter

Step 1: Install matplotlib

(python3runs01) $ pip3 install matplotlib
Collecting matplotlib
  Downloading https://files.pythonhosted.org/packages/71/07/16d781df15be30df4acfd536c479268f1208b2dfbc91e9ca5d92c9caf673/matplotlib-3.0.2-cp36-cp36m-manylinux1_x86_64.whl (12.9MB)
    100% |████████████████████████████████| 12.9MB 115kB/s 
Collecting python-dateutil>=2.1 (from matplotlib)
  Using cached https://files.pythonhosted.org/packages/74/68/d87d9b36af36f44254a8d512cbfc48369103a3b9e474be9bdfe536abfc45/python_dateutil-2.7.5-py2.py3-none-any.whl
Collecting numpy>=1.10.0 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/7b/74/54c5f9bb9bd4dae27a61ec1b39076a39d359b3fb7ba15da79ef23858a9d8/numpy-1.16.0-cp36-cp36m-manylinux1_x86_64.whl (17.3MB)
    100% |████████████████████████████████| 17.3MB 85kB/s 
Collecting kiwisolver>=1.0.1 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/69/a7/88719d132b18300b4369fbffa741841cfd36d1e637e1990f27929945b538/kiwisolver-1.0.1-cp36-cp36m-manylinux1_x86_64.whl (949kB)
    100% |████████████████████████████████| 952kB 1.4MB/s 
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/de/0a/001be530836743d8be6c2d85069f46fecf84ac6c18c7f5fb8125ee11d854/pyparsing-2.3.1-py2.py3-none-any.whl (61kB)
    100% |████████████████████████████████| 71kB 3.6MB/s 
Collecting cycler>=0.10 (from matplotlib)
  Using cached https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Collecting six>=1.5 (from python-dateutil>=2.1->matplotlib)
  Cache entry deserialization failed, entry ignored
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting setuptools (from kiwisolver>=1.0.1->matplotlib)
  Using cached https://files.pythonhosted.org/packages/bf/ae/a23db1762646069742cc21393833577d3fa438eecaa59d11fb04fa57fcd5/setuptools-40.7.1-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, numpy, setuptools, kiwisolver, pyparsing, cycler, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.0.1 matplotlib-3.0.2 numpy-1.16.0 pyparsing-2.3.1 python-dateutil-2.7.5 setuptools-40.7.1 six-1.12.0
$


Step 2: Install tkinter in ubuntu

(python3runs01) $ sudo apt-get install python3-tk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  blt libtcl8.6 libtk8.6 tk8.6-blt2.5
Suggested packages:
  blt-demo tcl8.6 tk8.6 tix python3-tk-dbg
The following NEW packages will be installed:
  blt libtcl8.6 libtk8.6 python3-tk tk8.6-blt2.5
0 upgraded, 5 newly installed, 0 to remove and 105 not upgraded.
Need to get 2,252 kB of archives.
After this operation, 9,233 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 libtcl8.6 amd64 8.6.8+dfsg-3 [881 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 libtk8.6 amd64 8.6.8-4 [693 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 tk8.6-blt2.5 amd64 2.5.3+dfsg-4 [572 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 blt amd64 2.5.3+dfsg-4 [4,944 B]
Get:5 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-tk amd64 3.6.7-1~18.04 [100 kB]
Fetched 2,252 kB in 2s (1,329 kB/s) 
Selecting previously unselected package libtcl8.6:amd64.
(Reading database ... 224648 files and directories currently installed.)
Preparing to unpack .../libtcl8.6_8.6.8+dfsg-3_amd64.deb ...
Unpacking libtcl8.6:amd64 (8.6.8+dfsg-3) ...
Selecting previously unselected package libtk8.6:amd64.
Preparing to unpack .../libtk8.6_8.6.8-4_amd64.deb ...
Unpacking libtk8.6:amd64 (8.6.8-4) ...
Selecting previously unselected package tk8.6-blt2.5.
Preparing to unpack .../tk8.6-blt2.5_2.5.3+dfsg-4_amd64.deb ...
Unpacking tk8.6-blt2.5 (2.5.3+dfsg-4) ...
Selecting previously unselected package blt.
Preparing to unpack .../blt_2.5.3+dfsg-4_amd64.deb ...
Unpacking blt (2.5.3+dfsg-4) ...
Selecting previously unselected package python3-tk:amd64.
Preparing to unpack .../python3-tk_3.6.7-1~18.04_amd64.deb ...
Unpacking python3-tk:amd64 (3.6.7-1~18.04) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up libtcl8.6:amd64 (8.6.8+dfsg-3) ...
Setting up libtk8.6:amd64 (8.6.8-4) ...
Setting up tk8.6-blt2.5 (2.5.3+dfsg-4) ...
Setting up blt (2.5.3+dfsg-4) ...
Setting up python3-tk:amd64 (3.6.7-1~18.04) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
(python3runs01) $


Let us now test by running the program in the following stackoverflow question:
https://stackoverflow.com/questions/31726643/how-do-i-get-multiple-subplots-in-matplotlib


Wednesday, January 30, 2019

Python - install WeasyPrint - python3



Install WeasyPrint in Python3:

(python3runs01) $ pip install WeasyPrint
Collecting WeasyPrint
  Downloading https://files.pythonhosted.org/packages/ec/0e/0d0f72e0832e9566f93d460676d8a34b2131f57424f5985604201a5102bf/WeasyPrint-44-py3-none-any.whl (354kB)
    100% |████████████████████████████████| 358kB 743kB/s 
Collecting Pyphen>=0.8 (from WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/15/82/08a3629dce8d1f3d91db843bb36d4d7db6b6269d5067259613a0d5c8a9db/Pyphen-0.9.5-py2.py3-none-any.whl (3.0MB)
    100% |████████████████████████████████| 3.0MB 3.5MB/s 
Collecting cairocffi>=0.9.0 (from WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/62/be/ad4d422b6f38d99b09ad6d046ab725e8ccac5fefd9ca256ca35a80dbf3c6/cairocffi-0.9.0.tar.gz (84kB)
    100% |████████████████████████████████| 92kB 7.1MB/s 
Collecting html5lib>=0.999999999 (from WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/a5/62/bbd2be0e7943ec8504b517e62bab011b4946e1258842bc159e5dfde15b96/html5lib-1.0.1-py2.py3-none-any.whl (117kB)
    100% |████████████████████████████████| 122kB 6.4MB/s 
Collecting cssselect2>=0.1 (from WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/12/e2/91fcd4cd32545beec6e11628d64d3e20f11b5a95dd1ccf3216fd69f176b7/cssselect2-0.2.1-py2.py3-none-any.whl
Collecting tinycss2>=0.5 (from WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/88/95/0ec73db7fc638ec000e662936ffe1a4e1eaa22f2861c8de18b1597c42584/tinycss2-0.6.1-py2.py3-none-any.whl (61kB)
    100% |████████████████████████████████| 71kB 14.9MB/s 
Collecting cffi>=0.6 (from WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/6d/c0/47db8f624f3e4e2f3f27be03a93379d1ba16a1450a7b1aacfa0366e2c0dd/cffi-1.11.5-cp36-cp36m-manylinux1_x86_64.whl (421kB)
    100% |████████████████████████████████| 430kB 10.2MB/s 
Collecting CairoSVG>=1.0.20 (from WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/5c/57/dadc80948bcb83ea9c0968ccfd5a1a25ace6be0884484526f70dad3c10b9/CairoSVG-2.2.1-py3-none-any.whl (52kB)
    100% |████████████████████████████████| 61kB 12.6MB/s 
Collecting webencodings (from html5lib>=0.999999999->WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl
Collecting six>=1.9 (from html5lib>=0.999999999->WeasyPrint)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting pycparser (from cffi>=0.6->WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)
    100% |████████████████████████████████| 163kB 13.0MB/s 
Collecting defusedxml (from CairoSVG>=1.0.20->WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/87/1c/17f3e3935a913dfe2a5ca85fa5ccbef366bfd82eb318b1f75dadbf0affca/defusedxml-0.5.0-py2.py3-none-any.whl
Collecting pillow (from CairoSVG>=1.0.20->WeasyPrint)
  Downloading https://files.pythonhosted.org/packages/85/5e/e91792f198bbc5a0d7d3055ad552bc4062942d27eaf75c3e2783cf64eae5/Pillow-5.4.1-cp36-cp36m-manylinux1_x86_64.whl (2.0MB)
    100% |████████████████████████████████| 2.0MB 5.4MB/s 
Building wheels for collected packages: cairocffi, pycparser
  Building wheel for cairocffi (setup.py) ... done
  Stored in directory: /home/mhc/.cache/pip/wheels/3a/2e/92/89e9dcce600a1a78bebe571fdd096669cba354b29c5e1140b9
  Building wheel for pycparser (setup.py) ... done
  Stored in directory: /home/mhc/.cache/pip/wheels/f2/9a/90/de94f8556265ddc9d9c8b271b0f63e57b26fb1d67a45564511
Successfully built cairocffi pycparser
Installing collected packages: Pyphen, pycparser, cffi, cairocffi, webencodings, six, html5lib, tinycss2, cssselect2, defusedxml, pillow, CairoSVG, WeasyPrint
Successfully installed CairoSVG-2.2.1 Pyphen-0.9.5 WeasyPrint-44 cairocffi-0.9.0 cffi-1.11.5 cssselect2-0.2.1 defusedxml-0.5.0 html5lib-1.0.1 pillow-5.4.1 pycparser-2.19 six-1.12.0 tinycss2-0.6.1 webencodings-0.5.1
(python3runs01) $ which pip
/opt3/python3runs01/bin/pip
(python3runs01) $ pip --version
pip 19.0.1 from /opt3/python3runs01/lib/python3.6/site-packages/pip (python 3.6)
(python3runs01)



Tuesday, January 29, 2019

Python - Using virtualenv - python3


Step 1: Create a virtual environment for python3:

/opt3$ virtualenv -p python3 python3runs01
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /opt3/python3runs01/bin/python3
Also creating executable in /opt3/python3runs01/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
/opt3$ 

Step 2: Change directory to the virtual environment folder:

/opt3$ cd python3runs01

Step 3: Activate the virtual environment:

/opt3/python3runs01$ source bin/activate
(python3runs01) /opt3/python3runs01$ 

Notice that, after you activate, a prompt is added. 
(python3runs01) /opt3/python3runs01$ ls -l
total 0
drwxr-xr-x 2 ubuntu ubuntu 320 Jan 29 11:50 bin
drwxr-xr-x 2 ubuntu ubuntu  60 Jan 29 11:50 include
drwxr-xr-x 3 ubuntu ubuntu  60 Jan 29 11:50 lib
drwxr-xr-x 3 ubuntu ubuntu  60 Jan 29 11:50 share
(python3runs01) /opt3/python3runs01$


Step 4: Deactivate from virtual environment:

(python3runs01) /opt3/python3runs01$ deactivate
/opt3/python3runs01$


References:

Thursday, January 24, 2019

Python - downgrade PIP

After upgrading PIP to version 10, I started to face issues with installation of python modules. Hence, I downgraded it to version 9 using the following command:

sudo pip install --force-reinstall pip==9.0.3

References:
https://github.com/pypa/pip/issues/5290