Tag: python

  • Jupyter Notebook

    Jupyter Notebook

    I have been programming with python for quite some time and been using Jupyter notebook for some data science projects, I like the UI and Jupter notebook provides with a web-based interactive development environment for python notebooks, code, and data.

    There are many blogs which will help you setup your notebook environment and itse really not difficult either and can be summarised in the following 4 commands

    $ python -m venv jupyter
    
    $ source jupyter/bin/activate
    
    $ pip install jupyter
    
    $ jupyter notebook

    Recently I tried to explore more on how I can possibly start jupyter notebook on my Android Device. The command does work on Android, but it comes with caveats. Here is somewhat quick detailed post on setting up Jupyter Notebook on Android Phone/Tablet.

    To run jupyter notebook, we require a working python development environment on Android.

    There are many ways to do this. I choose and prefer to use Termux App.

    Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically – additional packages are available using the APT package manager.

    – https://termux.com

    I have taken this install instruction from the stackoverflow answer with my amendments to it.

    1. Install the Termux app.
    2. Open Termux, then enter/run the following commands in the prompt:
      $ apt install clang python fftw libzmq freetype libpng pkg-config libcrypt
      $ LDFLAGS="-lm -lcompiler_rt" pip install jupyterFinally, test the notebook out by running:
    3. $ jupyter notebook
      

    When you run jupyter notebook, a notebook server starts up and dumps some information to stdout. When you see the line:

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:

    copy the following URL, paste it into the browser on your device, and then hit go. You should end up with something that looks like this:

    I tested these instructions out a Samsung Galaxy Tab 10 2020 (wifi) running stock Android 10 (10).

     

    I tried to provide as much details as pososble, but in case if i missed anything please let me know in the comments.

     

     

  • Python Virutal Environment on Windows

    I am an Unix SA and had been from quite a some time and used to work with my Windows Desktop in office and Linux Laptop at home, but during this lockdown I had been left with no choice but to work primarily on a Windows Laptop all the time, I really did not get much time to start my working and development environment, which also begs me to write an ansible playbook, which is for some later day blog. But here is the guide on which I would possible write my Playbook to install python and set thigs up.

    Prerequisites:

    • A Windows machine
    • Python installer (if you are the admin of the laptop then all good, otherwise installing this without admin account is another level challenge)
    • Knowledge of working with Windows Command Prompt. (Yes this is going to be totally different that working with Linux Command Prompt)

    The setup is quite simple, follow the steps below or just copy and paste all even that is all good.

    I am planning to use Python 3.8.3 installed on to my system.

    To check if python is installed on your laptop/workstation or not just type on the cmd prompt from the start menu or press “Win + R” -> “cmd”.

    Once the command prompt is open, type python on the c: prompt

    Display python version on Windows

    you should see something like in the screenshot .

    Type exit () to come out of the prompt, usual Linux “Ctrl +d” will not work in here. Windows has its own limitations.

    Next is to create a virtalenv, where we can do your project work.

    I have plans to make a video of this, which I will do sometime sooner for setting up python and virtualenv in windows. #TODO

    c:\>mkdir projects
    
    c:\>cd projects
    
    c:\projects>python -m venv my_first_python_program
    
    c:\projects>cd my_first_python_program
    
    c:\projects\my_first_python_program>dir
    
    c:\projects\my_first_python_program>cd Scripts
    
    c:\projects\my_first_python_program\Scripts>activate
    
    (my_first_python_program) c:\projects\my_first_python_program\Scripts>
    How to setup a virtual env in windows 10
    Steps to steps virtual env in windows

    Once you setup and activated the environment, the environment name is added as the prefix of the prompt.

    Till the time, you do not “deactivate” your virtual environment. you are not going make any changes to your core operating system libraries.

    Now, go download the pip libraries and modules and try out new things.

    (my_first_python_program) c:\projects\my_first_python_program\Scripts>pip install jupyter

    Finally, Coming out of the virtual enviromnet

    (my_first_python_program) c:\projects\my_first_python_program\Scripts>deactivate
    
    c:\projects\my_first_python_program\Scripts>

    Thank you for reading and bearing my adventours. 🙂

  • Ubuntu on Windows

    Today I was struggling to work on python virtual environment and realised that running a Python Virtual env in windows is not as simple and easy as compared to Linux, the difficulty here is attributed to two major things.

    • How to activate the virtual env (including installing and setting up python)
    • Where goes your virtualenv

    Unlilke Linux, where the projects directory is in my home dir, in windows it could possible be technically anywhere if you are the only user of your system. So I decided to install Ubuntu on my windows Laptop. I have heard earlier that Ubuntu comes compaitable with Windows 10. Installing and settingup Ubuntu on Windows is fairly easy but Before i jump on telling how you should set up Ubuntu on Linux here is my quick guide of setting up python development environment on windows.

    To Setup Ubuntu Desktop Let’s quickly go to Microsoft Store installed on your windows machine and Search for Ubuntu – I got the latest Ubuntu image as Ubuntu 20.04

    Ubuntu 20.4 in microsoft store

    Downloading Ubuntu doesn’t really make it work. We need to do some tweaking with our windows machine, before we can actually launch Ubuntu Linux.

    While I clicked on the Launch Button, I got this error

    Here we need to enable the Linux Subsystem for Windows, a detailed guide on how to enable the subsytem is provided by Microsoft here.

    Step 1 – Enable the Windows Subsystem for Linux

    Open PowerShell as Administrator and run:

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

    Step 2 – Enable Virtual machine feature

    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

    and thats it. Though i later on went ahead and got WLS2 enabled. The command and guide for that also given with the above document from Microsoft.