Tag: windows

  • 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.