Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Monday, July 29, 2019

Python - Opening Ipython Notebooks in Ubuntu

To be able to open Ipython Notebooks. We must install 2 modules using pip3.

  1. ipython
  2. notebook


Summary Installation Commands:

$ pip3 install ipython
$ pip3 install notebook

Once we install these modules, we can open an ipython notebook using the command:

$ ipython notebook MyNotebook-01.ipynb



Detailed Installation Commands:

Step 1: Install ipython

$ pip3 install ipython
Collecting ipython
  Downloading https://files.pythonhosted.org/packages/f6/c4/a79582814bdfe92bfca4d286a729304ffdf13f5135132cfcaea13cf1b2b3/ipython-7.7.0-py3-none-any.whl (774kB)
    100% |████████████████████████████████| 778kB 1.6MB/s 
Collecting pickleshare (from ipython)
  Downloading https://files.pythonhosted.org/packages/9a/41/220f49aaea88bc6fa6cba8d05ecf24676326156c23b991e80b3f2fc24c77/pickleshare-0.7.5-py2.py3-none-any.whl
Collecting pexpect; sys_platform != "win32" (from ipython)
  Downloading https://files.pythonhosted.org/packages/0e/3e/377007e3f36ec42f1b84ec322ee12141a9e10d808312e5738f52f80a232c/pexpect-4.7.0-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 6.1MB/s 
Collecting setuptools>=18.5 (from ipython)
  Using cached https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl
Collecting pygments (from ipython)
  Downloading https://files.pythonhosted.org/packages/5c/73/1dfa428150e3ccb0fa3e68db406e5be48698f2a979ccbcec795f28f44048/Pygments-2.4.2-py2.py3-none-any.whl (883kB)
    100% |████████████████████████████████| 890kB 1.4MB/s 
Collecting backcall (from ipython)
  Downloading https://files.pythonhosted.org/packages/84/71/c8ca4f5bb1e08401b916c68003acf0a0655df935d74d93bf3f3364b310e0/backcall-0.1.0.tar.gz
Collecting decorator (from ipython)
  Downloading https://files.pythonhosted.org/packages/5f/88/0075e461560a1e750a0dcbf77f1d9de775028c37a19a346a6c565a257399/decorator-4.4.0-py2.py3-none-any.whl
Collecting traitlets>=4.2 (from ipython)
  Downloading https://files.pythonhosted.org/packages/93/d6/abcb22de61d78e2fc3959c964628a5771e47e7cc60d53e9342e21ed6cc9a/traitlets-4.3.2-py2.py3-none-any.whl (74kB)
    100% |████████████████████████████████| 81kB 7.1MB/s 
Collecting jedi>=0.10 (from ipython)
  Downloading https://files.pythonhosted.org/packages/4e/06/e906725a5b3ad7996bbdbfe9958aab75db64ef84bbaabefe47574de58865/jedi-0.14.1-py2.py3-none-any.whl (1.0MB)
    100% |████████████████████████████████| 1.0MB 1.3MB/s 
Collecting prompt-toolkit<2.1.0,>=2.0.0 (from ipython)
  Downloading https://files.pythonhosted.org/packages/f7/a7/9b1dd14ef45345f186ef69d175bdd2491c40ab1dfa4b2b3e4352df719ed7/prompt_toolkit-2.0.9-py3-none-any.whl (337kB)
    100% |████████████████████████████████| 337kB 1.3MB/s 
Collecting ptyprocess>=0.5 (from pexpect; sys_platform != "win32"->ipython)
  Downloading https://files.pythonhosted.org/packages/d1/29/605c2cc68a9992d18dada28206eeada56ea4bd07a239669da41674648b6f/ptyprocess-0.6.0-py2.py3-none-any.whl
Collecting six (from traitlets>=4.2->ipython)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting ipython-genutils (from traitlets>=4.2->ipython)
  Downloading https://files.pythonhosted.org/packages/fa/bc/9bd3b5c2b4774d5f33b2d544f1460be9df7df2fe42f352135381c347c69a/ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting parso>=0.5.0 (from jedi>=0.10->ipython)
  Downloading https://files.pythonhosted.org/packages/a3/bd/bf4e5bd01d79906e5b945a7af033154da49fd2b0d5b5c705a21330323305/parso-0.5.1-py2.py3-none-any.whl (95kB)
    100% |████████████████████████████████| 102kB 2.0MB/s 
Collecting wcwidth (from prompt-toolkit<2.1.0,>=2.0.0->ipython)
  Downloading https://files.pythonhosted.org/packages/7e/9f/526a6947247599b084ee5232e4f9190a38f398d7300d866af3ab571a5bfe/wcwidth-0.1.7-py2.py3-none-any.whl
Building wheels for collected packages: backcall
  Running setup.py bdist_wheel for backcall ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/98/b0/dd/29e28ff615af3dda4c67cab719dd51357597eabff926976b45
Successfully built backcall
Installing collected packages: pickleshare, ptyprocess, pexpect, setuptools, pygments, backcall, decorator, six, ipython-genutils, traitlets, parso, jedi, wcwidth, prompt-toolkit, ipython
Successfully installed backcall-0.1.0 decorator-4.4.0 ipython-7.7.0 ipython-genutils-0.2.0 jedi-0.14.1 parso-0.5.1 pexpect-4.7.0 pickleshare-0.7.5 prompt-toolkit-2.0.9 ptyprocess-0.6.0 pygments-2.4.2 setuptools-41.0.1 six-1.12.0 traitlets-4.3.2 wcwidth-0.1.7
$


Step 2: Install Notebook:

$ pip3 install notebook
Collecting notebook
  Downloading https://files.pythonhosted.org/packages/4e/b6/a6189ca7146482d93c912dbe6c65db0f264c1c88f707feea3683caa6c1f8/notebook-6.0.0-py3-none-any.whl (9.0MB)
    100% |████████████████████████████████| 9.0MB 164kB/s 
Collecting jupyter-client>=5.3.1 (from notebook)
  Downloading https://files.pythonhosted.org/packages/af/4c/bf613864ae0644e2ac7d4a40bd209c40c8c71e3dc88d5f1d0aa92a68e716/jupyter_client-5.3.1-py2.py3-none-any.whl (91kB)
    100% |████████████████████████████████| 92kB 6.6MB/s 
Collecting Send2Trash (from notebook)
  Downloading https://files.pythonhosted.org/packages/49/46/c3dc27481d1cc57b9385aff41c474ceb7714f7935b1247194adae45db714/Send2Trash-1.5.0-py3-none-any.whl
Collecting prometheus-client (from notebook)
  Downloading https://files.pythonhosted.org/packages/b3/23/41a5a24b502d35a4ad50a5bb7202a5e1d9a0364d0c12f56db3dbf7aca76d/prometheus_client-0.7.1.tar.gz
Collecting traitlets>=4.2.1 (from notebook)
  Using cached https://files.pythonhosted.org/packages/93/d6/abcb22de61d78e2fc3959c964628a5771e47e7cc60d53e9342e21ed6cc9a/traitlets-4.3.2-py2.py3-none-any.whl
Collecting ipykernel (from notebook)
  Downloading https://files.pythonhosted.org/packages/a0/35/dd97fbb48d4e6b5ae97307497e31e46691adc2feedb6279d29fc1c8ad9c1/ipykernel-5.1.1-py3-none-any.whl (114kB)
    100% |████████████████████████████████| 122kB 8.9MB/s 
Collecting pyzmq>=17 (from notebook)
  Downloading https://files.pythonhosted.org/packages/92/92/ea8f20560d5f1d0c6eb3c7c67ca72abfb97307f4e6494fc05cc7c37904cf/pyzmq-18.0.2-cp36-cp36m-manylinux1_x86_64.whl (1.1MB)
    100% |████████████████████████████████| 1.1MB 1.2MB/s 
Collecting nbconvert (from notebook)
  Downloading https://files.pythonhosted.org/packages/35/e7/f46c9d65f149271e47fca6ab084ef5c6e4cb1870f4c5cce6690feac55231/nbconvert-5.5.0-py2.py3-none-any.whl (447kB)
    100% |████████████████████████████████| 450kB 2.5MB/s 
Collecting ipython-genutils (from notebook)
  Using cached https://files.pythonhosted.org/packages/fa/bc/9bd3b5c2b4774d5f33b2d544f1460be9df7df2fe42f352135381c347c69a/ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting jupyter-core>=4.4.0 (from notebook)
  Downloading https://files.pythonhosted.org/packages/e6/25/6ffb0f6e57fa6ef5d2f814377133b361b42a6dd39105f4885a4f1666c2c3/jupyter_core-4.5.0-py2.py3-none-any.whl (78kB)
    100% |████████████████████████████████| 81kB 6.8MB/s 
Collecting terminado>=0.8.1 (from notebook)
  Downloading https://files.pythonhosted.org/packages/a7/56/80ea7fa66565fa75ae21ce0c16bc90067530e5d15e48854afcc86585a391/terminado-0.8.2-py2.py3-none-any.whl
Collecting jinja2 (from notebook)
  Using cached https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl
Collecting nbformat (from notebook)
  Downloading https://files.pythonhosted.org/packages/da/27/9a654d2b6cc1eaa517d1c5a4405166c7f6d72f04f6e7eea41855fe808a46/nbformat-4.4.0-py2.py3-none-any.whl (155kB)
    100% |████████████████████████████████| 163kB 5.4MB/s 
Collecting tornado>=5.0 (from notebook)
  Downloading https://files.pythonhosted.org/packages/30/78/2d2823598496127b21423baffaa186b668f73cd91887fcef78b6eade136b/tornado-6.0.3.tar.gz (482kB)
    100% |████████████████████████████████| 491kB 2.4MB/s 
Collecting python-dateutil>=2.1 (from jupyter-client>=5.3.1->notebook)
  Using cached https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl
Collecting decorator (from traitlets>=4.2.1->notebook)
  Using cached https://files.pythonhosted.org/packages/5f/88/0075e461560a1e750a0dcbf77f1d9de775028c37a19a346a6c565a257399/decorator-4.4.0-py2.py3-none-any.whl
Collecting six (from traitlets>=4.2.1->notebook)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting ipython>=5.0.0 (from ipykernel->notebook)
  Using cached https://files.pythonhosted.org/packages/f6/c4/a79582814bdfe92bfca4d286a729304ffdf13f5135132cfcaea13cf1b2b3/ipython-7.7.0-py3-none-any.whl
Collecting entrypoints>=0.2.2 (from nbconvert->notebook)
  Downloading https://files.pythonhosted.org/packages/ac/c6/44694103f8c221443ee6b0041f69e2740d89a25641e62fb4f2ee568f2f9c/entrypoints-0.3-py2.py3-none-any.whl
Collecting defusedxml (from nbconvert->notebook)
  Using cached https://files.pythonhosted.org/packages/06/74/9b387472866358ebc08732de3da6dc48e44b0aacd2ddaa5cb85ab7e986a2/defusedxml-0.6.0-py2.py3-none-any.whl
Collecting pygments (from nbconvert->notebook)
  Using cached https://files.pythonhosted.org/packages/5c/73/1dfa428150e3ccb0fa3e68db406e5be48698f2a979ccbcec795f28f44048/Pygments-2.4.2-py2.py3-none-any.whl
Collecting bleach (from nbconvert->notebook)
  Downloading https://files.pythonhosted.org/packages/ab/05/27e1466475e816d3001efb6e0a85a819be17411420494a1e602c36f8299d/bleach-3.1.0-py2.py3-none-any.whl (157kB)
    100% |████████████████████████████████| 163kB 4.6MB/s 
Collecting testpath (from nbconvert->notebook)
  Downloading https://files.pythonhosted.org/packages/be/a4/162f9ebb6489421fe46dcca2ae420369edfee4b563c668d93cb4605d12ba/testpath-0.4.2-py2.py3-none-any.whl (163kB)
    100% |████████████████████████████████| 163kB 3.8MB/s 
Collecting pandocfilters>=1.4.1 (from nbconvert->notebook)
  Downloading https://files.pythonhosted.org/packages/4c/ea/236e2584af67bb6df960832731a6e5325fd4441de001767da328c33368ce/pandocfilters-1.4.2.tar.gz
Collecting mistune>=0.8.1 (from nbconvert->notebook)
  Downloading https://files.pythonhosted.org/packages/09/ec/4b43dae793655b7d8a25f76119624350b4d65eb663459eb9603d7f1f0345/mistune-0.8.4-py2.py3-none-any.whl
Collecting ptyprocess; os_name != "nt" (from terminado>=0.8.1->notebook)
  Using cached https://files.pythonhosted.org/packages/d1/29/605c2cc68a9992d18dada28206eeada56ea4bd07a239669da41674648b6f/ptyprocess-0.6.0-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from jinja2->notebook)
  Using cached https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
Collecting jsonschema!=2.5.0,>=2.4 (from nbformat->notebook)
  Downloading https://files.pythonhosted.org/packages/aa/69/df679dfbdd051568b53c38ec8152a3ab6bc533434fc7ed11ab034bf5e82f/jsonschema-3.0.1-py2.py3-none-any.whl (54kB)
    100% |████████████████████████████████| 61kB 7.0MB/s 
Collecting prompt-toolkit<2.1.0,>=2.0.0 (from ipython>=5.0.0->ipykernel->notebook)
  Using cached https://files.pythonhosted.org/packages/f7/a7/9b1dd14ef45345f186ef69d175bdd2491c40ab1dfa4b2b3e4352df719ed7/prompt_toolkit-2.0.9-py3-none-any.whl
Collecting pickleshare (from ipython>=5.0.0->ipykernel->notebook)
  Using cached https://files.pythonhosted.org/packages/9a/41/220f49aaea88bc6fa6cba8d05ecf24676326156c23b991e80b3f2fc24c77/pickleshare-0.7.5-py2.py3-none-any.whl
Collecting jedi>=0.10 (from ipython>=5.0.0->ipykernel->notebook)
  Using cached https://files.pythonhosted.org/packages/4e/06/e906725a5b3ad7996bbdbfe9958aab75db64ef84bbaabefe47574de58865/jedi-0.14.1-py2.py3-none-any.whl
Collecting pexpect; sys_platform != "win32" (from ipython>=5.0.0->ipykernel->notebook)
  Using cached https://files.pythonhosted.org/packages/0e/3e/377007e3f36ec42f1b84ec322ee12141a9e10d808312e5738f52f80a232c/pexpect-4.7.0-py2.py3-none-any.whl
Collecting setuptools>=18.5 (from ipython>=5.0.0->ipykernel->notebook)
  Using cached https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl
Collecting backcall (from ipython>=5.0.0->ipykernel->notebook)
Collecting webencodings (from bleach->nbconvert->notebook)
  Using cached https://files.pythonhosted.org/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl
Collecting pyrsistent>=0.14.0 (from jsonschema!=2.5.0,>=2.4->nbformat->notebook)
  Downloading https://files.pythonhosted.org/packages/b9/66/b2638d96a2d128b168d0dba60fdc77b7800a9b4a5340cefcc5fc4eae6295/pyrsistent-0.15.4.tar.gz (107kB)
    100% |████████████████████████████████| 112kB 6.5MB/s 
Collecting attrs>=17.4.0 (from jsonschema!=2.5.0,>=2.4->nbformat->notebook)
  Downloading https://files.pythonhosted.org/packages/23/96/d828354fa2dbdf216eaa7b7de0db692f12c234f7ef888cc14980ef40d1d2/attrs-19.1.0-py2.py3-none-any.whl
Collecting wcwidth (from prompt-toolkit<2.1.0,>=2.0.0->ipython>=5.0.0->ipykernel->notebook)
  Using cached https://files.pythonhosted.org/packages/7e/9f/526a6947247599b084ee5232e4f9190a38f398d7300d866af3ab571a5bfe/wcwidth-0.1.7-py2.py3-none-any.whl
Collecting parso>=0.5.0 (from jedi>=0.10->ipython>=5.0.0->ipykernel->notebook)
  Using cached https://files.pythonhosted.org/packages/a3/bd/bf4e5bd01d79906e5b945a7af033154da49fd2b0d5b5c705a21330323305/parso-0.5.1-py2.py3-none-any.whl
Building wheels for collected packages: prometheus-client, tornado, pandocfilters, pyrsistent
  Running setup.py bdist_wheel for prometheus-client ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/1c/54/34/fd47cd9b308826cc4292b54449c1899a30251ef3b506bc91ea
  Running setup.py bdist_wheel for tornado ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/84/bf/40/2f6ef700f48401ca40e5e3dd7d0e3c0a90e064897b7fe5fc08
  Running setup.py bdist_wheel for pandocfilters ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/39/01/56/f1b08a6275acc59e846fa4c1e1b65dbc1919f20157d9e66c20
  Running setup.py bdist_wheel for pyrsistent ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/bb/46/00/6d471ef0b813e3621f0abe6cb723c20d529d39a061de3f7c51
Successfully built prometheus-client tornado pandocfilters pyrsistent
Installing collected packages: pyzmq, tornado, decorator, six, ipython-genutils, traitlets, jupyter-core, python-dateutil, jupyter-client, Send2Trash, prometheus-client, wcwidth, prompt-toolkit, pickleshare, parso, jedi, pygments, ptyprocess, pexpect, setuptools, backcall, ipython, ipykernel, pyrsistent, attrs, jsonschema, nbformat, entrypoints, MarkupSafe, jinja2, defusedxml, webencodings, bleach, testpath, pandocfilters, mistune, nbconvert, terminado, notebook
Successfully installed MarkupSafe-1.1.1 Send2Trash-1.5.0 attrs-19.1.0 backcall-0.1.0 bleach-3.1.0 decorator-4.4.0 defusedxml-0.6.0 entrypoints-0.3 ipykernel-5.1.1 ipython-7.7.0 ipython-genutils-0.2.0 jedi-0.14.1 jinja2-2.10.1 jsonschema-3.0.1 jupyter-client-5.3.1 jupyter-core-4.5.0 mistune-0.8.4 nbconvert-5.5.0 nbformat-4.4.0 notebook-6.0.0 pandocfilters-1.4.2 parso-0.5.1 pexpect-4.7.0 pickleshare-0.7.5 prometheus-client-0.7.1 prompt-toolkit-2.0.9 ptyprocess-0.6.0 pygments-2.4.2 pyrsistent-0.15.4 python-dateutil-2.8.0 pyzmq-18.0.2 setuptools-41.0.1 six-1.12.0 terminado-0.8.2 testpath-0.4.2 tornado-6.0.3 traitlets-4.3.2 wcwidth-0.1.7 webencodings-0.5.1
$

Now, let us open out Ipython Notebook:


$ ipython notebook My-Notebook-01.ipynb
[TerminalIPythonApp] WARNING | Subcommand `ipython notebook` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter notebook` in the future
[I 11:00:41.831 NotebookApp] Writing notebook server cookie secret to /home/ubuntu/.local/share/jupyter/runtime/notebook_cookie_secret
[I 11:00:41.854 NotebookApp] Serving notebooks from local directory: /home/ubuntu/Documents/my-files-mooc/DS-Intro-Michigan/Course-01
[I 11:00:41.854 NotebookApp] The Jupyter Notebook is running at:
[I 11:00:41.854 NotebookApp] http://localhost:8888/?token=515a6aad1725091442d8a3060d2e07f2cbcc7888e8f79080
[I 11:00:41.854 NotebookApp]  or http://127.0.0.1:8888/?token=515a6aad1725091442d8a3060d2e07f2cbcc7888e8f79080
[I 11:00:41.854 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 11:00:41.860 NotebookApp] 
    
    To access the notebook, open this file in a browser:
        file:///home/ubuntu/.local/share/jupyter/runtime/nbserver-6937-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=515a6aad1725091442d8a3060d2e07f2cbcc7888e8f79080
     or http://127.0.0.1:8888/?token=515a6aad1725091442d8a3060d2e07f2cbcc7888e8f79080
Opening in existing browser session.
[E 11:00:43.502 NotebookApp] Could not open static file ''
[W 11:00:43.778 NotebookApp] 404 GET /static/components/react/react-dom.production.min.js (127.0.0.1) 8.66ms referer=http://localhost:8888/notebooks/week-02-Assignment-2.ipynb?token=515a6aad1725091442d8a3060d2e07f2cbcc7888e8f79080
[I 11:00:45.545 NotebookApp] Writing notebook-signing key to /home/ubuntu/.local/share/jupyter/notebook_secret
[W 11:00:45.549 NotebookApp] Notebook week-02-Assignment-2.ipynb is not trusted
[W 11:00:45.569 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20190729110041 (127.0.0.1) 1017.94ms referer=http://localhost:8888/notebooks/week-02-Assignment-2.ipynb
[I 11:00:46.862 NotebookApp] Kernel started: ac83c589-65d2-48a5-89f6-ce330f81bdfd
[I 11:00:47.679 NotebookApp] Adapting from protocol version 5.1 (kernel ac83c589-65d2-48a5-89f6-ce330f81bdfd) to 5.3 (client).
[I 11:02:06.999 NotebookApp] Starting buffering for ac83c589-65d2-48a5-89f6-ce330f81bdfd:351843f1bd364e348e9980cff4586dee
^C[I 11:05:58.555 NotebookApp] interrupted
Serving notebooks from local directory: /home/ubuntu/Documents/
1 active kernel
The Jupyter Notebook is running at:
http://localhost:8888/?token=515a6aad1725091442d8a3060d2e07f2cbcc7888e8f79080
 or http://127.0.0.1:8888/?token=515a6aad1725091442d8a3060d2e07f2cbcc7888e8f79080



Success!

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

Monday, December 31, 2018

Python - Using virtualenv

Step1: Create a virtual environment:

/opt3$ virtualenv runs02
Running virtualenv with interpreter /usr/bin/python2
New python executable in /opt3/runs02/bin/python2
Also creating executable in /opt3/runs02/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
/opt3$

Step 2: Activate the environment:

$ cd runs02
/opt3/runs02$ ls -l
total 0
drwxr-xr-x 2 mhc mhc 320 Dec 31 12:51 bin
drwxr-xr-x 2 mhc mhc  60 Dec 31 12:51 include
drwxr-xr-x 3 mhc mhc  60 Dec 31 12:51 lib
drwxr-xr-x 2 mhc mhc 100 Dec 31 12:51 local
drwxr-xr-x 3 mhc mhc  60 Dec 31 12:51 share
/opt3/runs02$ which source
opt3/runs02$ $ source bin/activate
(runs02) /opt3/runs02$

Step 3: Now install the needed packages using pip.

Installing pandas:

(runs02) /opt3/runs02$ pip install pandas
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/b7/e3/f52d484244105fa3d558ce8217a5190cd3d40536076bef66d92d01566325/pandas-0.23.4-cp27-cp27mu-manylinux1_x86_64.whl (8.9MB)
    100% |████████████████████████████████| 8.9MB 2.2MB/s 
Collecting pytz>=2011k (from pandas)
  Downloading https://files.pythonhosted.org/packages/f8/0e/2365ddc010afb3d79147f1dd544e5ee24bf4ece58ab99b16fbb465ce6dc0/pytz-2018.7-py2.py3-none-any.whl (506kB)
    100% |████████████████████████████████| 512kB 10.7MB/s 
Collecting numpy>=1.9.0 (from pandas)
  Downloading https://files.pythonhosted.org/packages/de/37/fe7db552f4507f379d81dcb78e58e05030a8941757b1f664517d581b5553/numpy-1.15.4-cp27-cp27mu-manylinux1_x86_64.whl (13.8MB)
    100% |████████████████████████████████| 13.8MB 1.4MB/s 
Requirement already satisfied: python-dateutil>=2.5.0 in ./lib/python2.7/site-packages (from pandas) (2.7.5)
Requirement already satisfied: six>=1.5 in ./lib/python2.7/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)
Installing collected packages: pytz, numpy, pandas
Successfully installed numpy-1.15.4 pandas-0.23.4 pytz-2018.7
(runs02) /opt3/runs02$



Reference:

Wednesday, August 15, 2018

Python - Machine Learning - using tree with Iris dataset to predict

We can use the below code snippet to perform prediction on Iris dataset.
from sklearn.datasets import load_iris
from sklearn import tree
iris = load_iris()
print(list(iris.target_names))
classifier = tree.DecisionTreeClassifier()
classifier = classifier.fit(iris.data, iris.target)
print(classifier.predict([[5.1,3.5,1.4,1.5]]))


Refer:

Python - Machine Learning - Install scikit-learn in Ubuntu



To install scikit-learn package, we need to install its dependencies:

$ sudo pip install scipy
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting scipy
  Downloading https://files.pythonhosted.org/packages/2a/f3/de9c1bd16311982711209edaa8c6caa962db30ebb6a8cc6f1dcd2d3ef616/scipy-1.1.0-cp27-cp27mu-manylinux1_x86_64.whl (30.8MB)
    100% |████████████████████████████████| 30.8MB 38kB/s 
Requirement already satisfied: numpy>=1.8.2 in ./.local/lib/python2.7/site-packages (from scipy)
Installing collected packages: scipy
Successfully installed scipy-1.1.0
$


Now Install sklearn:

$ sudo pip install sklearn
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting sklearn
  Downloading https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz
Collecting scikit-learn (from sklearn)
  Downloading https://files.pythonhosted.org/packages/bc/67/370aa248f54769a56216707ad7b9af19745e85a603fafa47bde353f327fb/scikit_learn-0.19.2-cp27-cp27mu-manylinux1_x86_64.whl (5.0MB)
    100% |████████████████████████████████| 5.0MB 179kB/s 
Installing collected packages: scikit-learn, sklearn
  Running setup.py install for sklearn ... done
Successfully installed scikit-learn-0.19.2 sklearn-0.0
$

Refer:

Tuesday, June 19, 2018

Python - Installing virtualenv in Ubuntu

Use the below command to install virtualenv in Ubuntu:

$ sudo apt-get install virtualenv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  python3-virtualenv
The following NEW packages will be installed:
  python3-virtualenv virtualenv
0 upgraded, 2 newly installed, 0 to remove and 9 not upgraded.
Need to get 47.8 kB of archives.
After this operation, 171 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/universe amd64 python3-virtualenv all 15.1.0+ds-1.1 [43.4 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 virtualenv all 15.1.0+ds-1.1 [4,476 B]
Fetched 47.8 kB in 1s (49.2 kB/s)     
Selecting previously unselected package python3-virtualenv.
(Reading database ... 205693 files and directories currently installed.)
Preparing to unpack .../python3-virtualenv_15.1.0+ds-1.1_all.deb ...
Unpacking python3-virtualenv (15.1.0+ds-1.1) ...
Selecting previously unselected package virtualenv.
Preparing to unpack .../virtualenv_15.1.0+ds-1.1_all.deb ...
Unpacking virtualenv (15.1.0+ds-1.1) ...
Setting up python3-virtualenv (15.1.0+ds-1.1) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up virtualenv (15.1.0+ds-1.1) ...



Refer:

Python - Install Jinja - template engine

Install Jinja2 templating engine using pip:

$ sudo pip install Jinja2
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting Jinja2
  Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)
    100% |████████████████████████████████| 133kB 374kB/s 
Collecting MarkupSafe>=0.23 (from Jinja2)
  Downloading https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz
Installing collected packages: MarkupSafe, Jinja2
  Running setup.py install for MarkupSafe ... done
Successfully installed Jinja2-2.10 MarkupSafe-1.0



Check Installation:

$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import jinja2 
>>> exit()
$

Installation successful.

Python - PDF reports module - weasyprint - install

Follow the below steps to install weasyprint module for python on Ubuntu 18.04:

Step 1: Install the dependencies for weasyprint:

Install dependencies using the command:
sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info



Step 2: Install using pip :

$ sudo pip install weasyprint
[sudo] password for ubuntu: 
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting weasyprint
  Downloading https://files.pythonhosted.org/packages/7e/4c/cf2ec7abf7f84a2d1325d01dcac1d4bcb77f41117101fe564eb76952c65f/WeasyPrint-0.42.3.tar.gz (399kB)
    100% |████████████████████████████████| 409kB 1.4MB/s 
Collecting Pyphen>=0.8 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/dd/c4/74859f895e2361d92cfbb6208ea7afd06c2f1f05c491da71cbd7ce3887be/Pyphen-0.9.4-py2.py3-none-any.whl (1.9MB)
    100% |████████████████████████████████| 2.0MB 516kB/s 
Collecting cairocffi>=0.5 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/7a/2f/78179fea3413322fd20be407897738e5569e876e7cb6e4647a79b1ffd8dd/cairocffi-0.8.1.tar.gz (79kB)
    100% |████████████████████████████████| 81kB 2.9MB/s 
Collecting cffi>=0.6 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/14/dd/3e7a1e1280e7d767bd3fa15791759c91ec19058ebe31217fe66f3e9a8c49/cffi-1.11.5-cp27-cp27mu-manylinux1_x86_64.whl (407kB)
    100% |████████████████████████████████| 409kB 1.5MB/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 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 2.5MB/s 
Collecting pdfrw>=0.4 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/c0/84/af442c4458756bb0c0d2424102d1200616f3ff9b82c48aaa130e08549bf6/pdfrw-0.4-py2.py3-none-any.whl (69kB)
    100% |████████████████████████████████| 71kB 2.9MB/s 
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 3.6MB/s 
Collecting CairoSVG<2.0.0,>=1.0.20 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/d9/9b/c241990c86faa9e52a01f0570bba4247ba0f3d66eae2607e179cb9ae773a/CairoSVG-1.0.22.tar.gz
Collecting pycparser (from cffi>=0.6->weasyprint)
  Downloading https://files.pythonhosted.org/packages/8c/2d/aad7f16146f4197a11f8e91fb81df177adcc2073d36a17b1491fd09df6ed/pycparser-2.18.tar.gz (245kB)
    100% |████████████████████████████████| 256kB 2.1MB/s 
Requirement already satisfied: six>=1.9 in ./.local/lib/python2.7/site-packages (from html5lib>=0.999999999->weasyprint)
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
Installing collected packages: Pyphen, pycparser, cffi, cairocffi, webencodings, tinycss2, cssselect2, html5lib, pdfrw, CairoSVG, weasyprint
  Running setup.py install for pycparser ... done
  Running setup.py install for cairocffi ... done
  Running setup.py install for CairoSVG ... done
  Running setup.py install for weasyprint ... done
Successfully installed CairoSVG-1.0.22 Pyphen-0.9.4 cairocffi-0.8.1 cffi-1.11.5 cssselect2-0.2.1 html5lib-1.0.1 pdfrw-0.4 pycparser-2.18 tinycss2-0.6.1 weasyprint-0.42.3 webencodings-0.5.1
$

Check the installation:

$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import weasyprint
>>> exit()

Installation is successful.

Wednesday, April 11, 2018

Python - calculate arctangent in radians and degrees

We know that the arctangent of 1 is 45 degrees or pi/4 radians. Now, let see how we can calculate the value using python:

Using Numpy:

import numpy
import math
numpy.arctan(1) # calculates in radians
0.78539816339744828
numpy.arctan(1)*180/math.pi # calculates in degrees
45.0

Using regular python:

import math
math.atan(1) # calculates in radians
0.7853981633974483
math.atan(1)*180/math.pi # calculates in degrees
45.0





References:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.arctan.html
https://docs.python.org/2/library/math.html#math.atan

Friday, April 6, 2018

Python - download youtube videos

To download youtube videos, we need to install the module: youtube-dl

$ sudo pip install youtube-dl

Check File Types: To check out the filetypes available for downloading, we use the following command:

$ youtube-dl -F https://www.youtube.com/watch?v=2eumjKINo6w
WARNING: Assuming --restrict-filenames since file system encoding cannot encode all characters. Set the LC_ALL environment variable to fix this.
[youtube] 2eumjKINo6w: Downloading webpage
[youtube] 2eumjKINo6w: Downloading video info webpage
[youtube] 2eumjKINo6w: Extracting video information
WARNING: unable to extract uploader nickname
[info] Available formats for 2eumjKINo6w:
format code  extension  resolution note
249          webm       audio only DASH audio   51k , opus @ 50k, 3.56MiB
250          webm       audio only DASH audio   55k , opus @ 70k, 4.06MiB
171          webm       audio only DASH audio   89k , vorbis@128k, 6.32MiB
251          webm       audio only DASH audio  127k , opus @160k, 9.37MiB
140          m4a        audio only DASH audio  128k , m4a_dash container, mp4a.40.2@128k, 9.66MiB
278          webm       256x144    144p   96k , webm container, vp9, 15fps, video only, 6.22MiB
160          mp4        256x144    144p  117k , avc1.42c00c, 15fps, video only, 8.63MiB
242          webm       426x240    240p  216k , vp9, 30fps, video only, 8.97MiB
133          mp4        426x240    240p  248k , avc1.4d4015, 30fps, video only, 18.57MiB
243          webm       640x360    360p  417k , vp9, 30fps, video only, 18.09MiB
134          mp4        640x360    360p  534k , avc1.4d401e, 30fps, video only, 23.52MiB
244          webm       854x480    480p  758k , vp9, 30fps, video only, 32.44MiB
135          mp4        854x480    480p 1082k , avc1.4d401f, 30fps, video only, 49.89MiB
247          webm       1280x720   720p 1455k , vp9, 30fps, video only, 74.34MiB
136          mp4        1280x720   720p 2065k , avc1.4d401f, 30fps, video only, 99.03MiB
248          webm       1920x1080  1080p 2791k , vp9, 30fps, video only, 170.39MiB
137          mp4        1920x1080  1080p 4141k , avc1.640028, 30fps, video only, 208.59MiB
17           3gp        176x144    small , mp4v.20.3, mp4a.40.2@ 24k
36           3gp        320x180    small , mp4v.20.3, mp4a.40.2
43           webm       640x360    medium , vp8.0, vorbis@128k
18           mp4        640x360    medium , avc1.42001E, mp4a.40.2@ 96k
22           mp4        1280x720   hd720 , avc1.64001F, mp4a.40.2@192k (best)
 $


Download video of a particular filetype:

$ youtube-dl -f 18 https://www.youtube.com/watch?v=2eumjKINo6w
WARNING: Assuming --restrict-filenames since file system encoding cannot encode all characters. Set the LC_ALL environment variable to fix this.
[youtube] 2eumjKINo6w: Downloading webpage
[youtube] 2eumjKINo6w: Downloading video info webpage
[youtube] 2eumjKINo6w: Extracting video information
WARNING: unable to extract uploader nickname
[download] Destination: The_Story_of_Integration_2_of_4_-_Riemann_s_Integral-2eumjKINo6w.mp4
[download] 100% of 30.23MiB in 00:01
 $ 

Notice, the -f flag used.

Downloading the entire playlist can be done by using the below command:

$ youtube-dl -f 18 -o '%(playlist_index)s. %(title)s.%(ext)s'  https://www.youtube.com/playlist?list=PLrsBhRPS9dWHGfBTLJcmeopwjbTCn6cUe
WARNING: Assuming --restrict-filenames since file system encoding cannot encode all characters. Set the LC_ALL environment variable to fix this.
[youtube:playlist] PLrsBhRPS9dWHGfBTLJcmeopwjbTCn6cUe: Downloading webpage
[download] Downloading playlist: Khan Academy Linear Algebra | Vectors and spaces
[youtube:playlist] playlist Khan Academy Linear Algebra | Vectors and spaces: Downloading 41 videos
[download] Downloading video 1 of 41
[youtube] br7tS1t2SFE: Downloading webpage
[youtube] br7tS1t2SFE: Downloading video info webpage
[youtube] br7tS1t2SFE: Extracting video information
WARNING: unable to extract uploader nickname
[download] Destination: 01. Vector_intro_for_linear_algebra_Vectors_and_spaces_Linear_Algebra_Khan_Academy.mp4
[download] 100% of 4.44MiB in 00:00
[download] Downloading video 2 of 41
[youtube] lCsjJbZHhHU: Downloading webpage
[youtube] lCsjJbZHhHU: Downloading video info webpage
[youtube] lCsjJbZHhHU: Extracting video information
WARNING: unable to extract uploader nickname
[download] Destination: 02. Real_coordinate_spaces_Vectors_and_spaces_Linear_Algebra_Khan_Academy.mp4


Notice here, the -o flag used.