Wednesday, August 7, 2019

Python3 - Ubuntu - Apache - Access Anaconda python library from apache

The apache server has its own path. To make change to the PATH variable, we need to change in the file: /etc/apache2/envvars

$ sudo vi /etc/apache2/envvars


At the end of this file. I added the path of anaconda3 library:

export PATH=/opt/anaconda3/bin:$PATH


Created a small test script to confirm if the path is correct:

$ more test1.php
<?php
$output = shell_exec('echo $PATH');
echo "<pre>$output</pre>";
?>
$ 


This gives the following output:

/opt/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin


Hence, we can ensure that our apache2 user is able to access anaconda library of python.

Reference:


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!

Monday, June 17, 2019

NodeJS - Application Entry Point - app.js

In a node.js application that uses multiple files the main entry point of the application is often called app.js - this is a Node.js community convention. So we should be able to run a Node.js application as:

$ node app.js



References:


Thursday, May 30, 2019

Python - Bokeh - Download DataSets


On trying the example at: https://bokeh.pydata.org/en/latest/docs/gallery/texas.html , I received the following error:

RuntimeError: bokeh sample data directory does not exist, please execute bokeh.sampledata.download()

Hence, I executed the following as suggested in the message:

>>> import bokeh.sampledata
>>> bokeh.sampledata.download()
Creating /home/mhc/.bokeh directory
Creating /home/mhc/.bokeh/data directory
Using data directory: /home/mhc/.bokeh/data
Downloading: CGM.csv (1589982 bytes)
   1589982 [100.00%]
Downloading: US_Counties.zip (3171836 bytes)
   3171836 [100.00%]
Unpacking: US_Counties.csv
Downloading: us_cities.json (713565 bytes)
    713565 [100.00%]
Downloading: unemployment09.csv (253301 bytes)
    253301 [100.00%]
Downloading: AAPL.csv (166698 bytes)
    166698 [100.00%]
Downloading: FB.csv (9706 bytes)
      9706 [100.00%]
Downloading: GOOG.csv (113894 bytes)
    113894 [100.00%]
Downloading: IBM.csv (165625 bytes)
    165625 [100.00%]
Downloading: MSFT.csv (161614 bytes)
    161614 [100.00%]
Downloading: WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.zip (4816256 bytes)
   4816256 [100.00%]
Unpacking: WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.csv
Downloading: gapminder_fertility.csv (64346 bytes)
     64346 [100.00%]
Downloading: gapminder_population.csv (94509 bytes)
     94509 [100.00%]
Downloading: gapminder_life_expectancy.csv (73243 bytes)
     73243 [100.00%]
Downloading: gapminder_regions.csv (7781 bytes)
      7781 [100.00%]
Downloading: world_cities.zip (645274 bytes)
    645274 [100.00%]
Unpacking: world_cities.csv
Downloading: airports.json (6373 bytes)
      6373 [100.00%]
Downloading: movies.db.zip (5053420 bytes)
   5053420 [100.00%]
Unpacking: movies.db
Downloading: airports.csv (203190 bytes)
    203190 [100.00%]
Downloading: routes.csv (377280 bytes)
    377280 [100.00%]
Downloading: haarcascade_frontalface_default.xml (930127 bytes)
    930127 [100.00%]
>>> 

This has downloaded all the bokeh datasets.

Sunday, April 21, 2019

JavaScript - Angular - Installing Angular Material Module and dependencies

In order to install angular material module.  Let us install the following:

  • npm install @angular/material@6.4.7 --save
  • npm install @angular/cdk@6.4.7 --save
  • npm install @angular/animations@6.1.7 --save
  • npm install hammerjs@2.0.8 --save


Now, let us install the flex layout module:

$  npm install --save @angular/flex-layout@6.0.0-beta.18
npm WARN @angular/animations@6.1.7 requires a peer of @angular/core@6.1.7 but none is installed. You must install peer dependencies yourself.
npm WARN ajv-keywords@3.4.0 requires a peer of ajv@^6.9.1 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.8 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.8: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ @angular/flex-layout@6.0.0-beta.18
added 1 package in 11.902s




JavaScript - Angular - Installing Angular of a specific version

Installing Angular of a specific version using npm:

$ npm install -g @angular/cli@6.2.1
/home/ubuntu/.nvm/versions/node/v8.11.1/bin/ng -> /home/ubuntu/.nvm/versions/node/v8.11.1/lib/node_modules/@angular/cli/bin/ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.8 (node_modules/@angular/cli/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.8: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ @angular/cli@6.2.1
added 5 packages, removed 6 packages and updated 27 packages in 11.412s


Now to check the options available with the ng command:

$ ng help
Available Commands:
  add Add support for a library to your project.
  build (b) Builds your app and places it into the output path (dist/ by default).
  config Get/set configuration values.
  doc (d) Opens the official Angular API documentation for a given keyword.
  e2e (e) 
  generate (g) Generates and/or modifies files based on a schematic.
  help Displays help for the Angular CLI.
  lint (l) Lints code in existing project.
  new (n) Creates a new directory and a new Angular app.
  run Runs Architect targets.
  serve (s) Builds and serves your app, rebuilding on file changes.
  test (t) Run unit tests in existing project.
  update Updates your application and its dependencies.
  version (v) Outputs Angular CLI version.
  xi18n Extracts i18n messages from source code.

For more detailed help run "ng [command name] --help"
$


To check for the version details:

$ ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 6.2.1
Node: 8.11.1
OS: linux x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.8.1
@angular-devkit/core         0.8.1
@angular-devkit/schematics   0.8.1
@schematics/angular          0.8.1
@schematics/update           0.8.1
rxjs                         6.2.2
typescript                   2.9.2
    
$ 

Now, let us setup one application:

$ ng new myNgApp2 --style=sass
CREATE myNgApp2/README.md (1025 bytes)
CREATE myNgApp2/angular.json (3653 bytes)
CREATE myNgApp2/package.json (1316 bytes)
CREATE myNgApp2/tsconfig.json (408 bytes)
CREATE myNgApp2/tslint.json (2837 bytes)
CREATE myNgApp2/.editorconfig (245 bytes)
CREATE myNgApp2/.gitignore (503 bytes)
CREATE myNgApp2/src/favicon.ico (5430 bytes)
CREATE myNgApp2/src/index.html (295 bytes)
CREATE myNgApp2/src/main.ts (371 bytes)
CREATE myNgApp2/src/polyfills.ts (3194 bytes)
CREATE myNgApp2/src/test.ts (642 bytes)
CREATE myNgApp2/src/styles.sass (80 bytes)
CREATE myNgApp2/src/browserslist (388 bytes)
CREATE myNgApp2/src/karma.conf.js (964 bytes)
CREATE myNgApp2/src/tsconfig.app.json (166 bytes)
CREATE myNgApp2/src/tsconfig.spec.json (256 bytes)
CREATE myNgApp2/src/tslint.json (314 bytes)
CREATE myNgApp2/src/assets/.gitkeep (0 bytes)
CREATE myNgApp2/src/environments/environment.prod.ts (51 bytes)
CREATE myNgApp2/src/environments/environment.ts (662 bytes)
CREATE myNgApp2/src/app/app.module.ts (314 bytes)
CREATE myNgApp2/src/app/app.component.sass (0 bytes)
CREATE myNgApp2/src/app/app.component.html (1141 bytes)
CREATE myNgApp2/src/app/app.component.spec.ts (1001 bytes)
CREATE myNgApp2/src/app/app.component.ts (213 bytes)
CREATE myNgApp2/e2e/protractor.conf.js (752 bytes)
CREATE myNgApp2/e2e/tsconfig.e2e.json (213 bytes)
CREATE myNgApp2/e2e/src/app.e2e-spec.ts (304 bytes)
CREATE myNgApp2/e2e/src/app.po.ts (208 bytes)
npm WARN deprecated @angular/http@6.1.10: Switch to @angular/common/http - see https://angular.io/guide/http
npm WARN deprecated istanbul@0.4.5: This module is no longer maintained, try this instead:
npm WARN deprecated   npm i nyc
npm WARN deprecated Visit https://istanbul.js.org/integrations for other alternatives.
npm WARN deprecated circular-json@0.5.9: CircularJSON is in maintenance only, flatted is its successor.

> node-sass@4.11.0 install /home/ubuntu/Documents/ngWorks/jogesh/myNgApp2/node_modules/node-sass
> node scripts/install.js

Cached binary found at /home/ubuntu/.npm/node-sass/4.11.0/linux-x64-57_binding.node

> node-sass@4.11.0 postinstall /home/ubuntu/Documents/ngWorks/jogesh/myNgApp2/node_modules/node-sass
> node scripts/build.js

Binary found at /home/ubuntu/Documents/ngWorks/jogesh/myNgApp2/node_modules/node-sass/vendor/linux-x64-57/binding.node
Testing binary
Binary is fine
npm WARN ajv-keywords@3.4.0 requires a peer of ajv@^6.9.1 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.8 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.8: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 1142 packages in 30.052s
    Successfully initialized git.
$ 

Now, let type the following command:
$ npm install
npm WARN ajv-keywords@3.4.0 requires a peer of ajv@^6.9.1 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.8 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.8: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

up to date in 8.378s


Now, let us type :

$ ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
 10% building modules 3/3 modules 0 active                         



The app is now available on localhost at: http://localhost:4200/

This is a very simple bare bones application to help us get started with angular. Now, if we check the git:

$ git log --oneline
e222cd0 (HEAD -> master) initial commit



Monday, February 25, 2019

Ubuntu - Installing fonts quickly



To be able to install fonts in ubuntu quickly, I found the following link useful:
https://askubuntu.com/questions/191778/how-to-install-many-font-files-quickly-and-easily


Step 1: Create the path in home directory:
$ mkdir ~/.fonts

Step 2: Place the fonts in this folder:

~/.fonts$ ls -l
total 2096
drwxr-xr-x 2 ubuntu ubuntu    4096 Feb 25 11:02 league-spartan
-rw-rw-r-- 1 ubuntu ubuntu   21379 Feb 25 10:59 league-spartan.zip
drwxrwxr-x 2 ubuntu ubuntu    4096 Nov 29 13:15 Montserrat
-rw-rw-r-- 1 ubuntu ubuntu 2104101 Feb 25 10:59 Montserrat.zip
~/.fonts$ 

Step 3: Install the fonts using the command:

~/.fonts/Montserrat$ fc-cache -f -v
/usr/share/fonts: caching, new cache contents: 0 fonts, 6 dirs
/usr/share/fonts/X11: caching, new cache contents: 0 fonts, 4 dirs
/usr/share/fonts/X11/Type1: caching, new cache contents: 8 fonts, 0 dirs
/usr/share/fonts/X11/encodings: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/X11/encodings/large: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/X11/misc: caching, new cache contents: 89 fonts, 0 dirs
/usr/share/fonts/X11/util: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/cMap: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/cmap: caching, new cache contents: 0 fonts, 5 dirs
/usr/share/fonts/cmap/adobe-cns1: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/cmap/adobe-gb1: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/cmap/adobe-japan1: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/cmap/adobe-japan2: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/cmap/adobe-korea1: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/opentype: caching, new cache contents: 0 fonts, 2 dirs
/usr/share/fonts/opentype/malayalam: caching, new cache contents: 3 fonts, 0 dirs
/usr/share/fonts/opentype/noto: caching, new cache contents: 24 fonts, 0 dirs
/usr/share/fonts/truetype: caching, new cache contents: 0 fonts, 46 dirs
/usr/share/fonts/truetype/Gargi: caching, new cache contents: 1 fonts, 0 dirs
/usr/share/fonts/truetype/Gubbi: caching, new cache contents: 1 fonts, 0 dirs
/usr/share/fonts/truetype/Nakula: caching, new cache contents: 1 fonts, 0 dirs
/usr/share/fonts/truetype/tibetan-machine: caching, new cache contents: 1 fonts, 0 dirs
/usr/share/fonts/truetype/tlwg: caching, new cache contents: 58 fonts, 0 dirs
/usr/share/fonts/truetype/ttf-khmeros-core: caching, new cache contents: 2 fonts, 0 dirs
/usr/share/fonts/truetype/ubuntu: caching, new cache contents: 13 fonts, 0 dirs
/usr/share/fonts/type1: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/type1/gsfonts: caching, new cache contents: 35 fonts, 0 dirs
/usr/local/share/fonts: caching, new cache contents: 0 fonts, 0 dirs
/home/mhc/.local/share/fonts: caching, new cache contents: 1 fonts, 0 dirs
/home/mhc/.fonts: caching, new cache contents: 0 fonts, 2 dirs
/home/mhc/.fonts/Montserrat: caching, new cache contents: 18 fonts, 0 dirs
/home/mhc/.fonts/league-spartan: caching, new cache contents: 1 fonts, 0 dirs
/var/cache/fontconfig: not cleaning unwritable cache directory
/home/mhc/.cache/fontconfig: cleaning cache directory
/home/mhc/.fontconfig: not cleaning non-existent cache directory
fc-cache: succeeded
~/.fonts/Montserrat$

We can verify that the fonts are installed by opening LibreOffice writer and typing the content is a particular font.