Showing posts with label python3. Show all posts
Showing posts with label python3. Show all posts

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!

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.

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: