#

Saturday, February 1, 2025

Creating a Room for DevNet - Getting Started with Python & Developing


This post is about making a virtual machine dedicated for DevNet things, Python and all. This is how I am doing it with the already available tools, sharing it with someone who is getting into the DevNet.

I still use Ubuntu 20.04 for my developing work. I didn't upgrade it as Ubuntu is good at braking things with their new updates. I run it in VMWare workstation in my Windows PC with very minimal requirements.

HDD: 30GB dedicated on a SSD
RAM: 8GB
OS: Ubuntu 20.04
Processors: 2 (from 2.5 GHz base speed)
Cores per Processor: 1

As soon as you are done with basic Ubuntu installation, let's install basic tools to practice Python.

Update
sudo apt update

Install Python 3.9
sudo apt-add-repository ppa:deadsnakes/ppa
sudo apt install python3.9

verify your installation
python3.9 --version




Install Git,
sudo apt install git

you can check the version with,
git --version




Install Visual Studio Code
sudo snap install --classic code

You can launch VS Code from command code in terminal.

Install following extensions in VS Code.

Python
Cisco IOS Syntax
Better Jinja
Remote - SSH

And the list will go on, but above will be the basics.

Monokai Pro is something coders use for better readability, I use it too, but that's optional.

If an error popped up saying, "No Python interpreter installed"  just click on it and select Python 3.9.6 64-bit but mostly this is not required.










Virtual Environments (.venv)

It is like create your own little space within Linux Terminal, you can just run different versions of different packages without conflicting.  

How to create?

Install python3-venv first,
sudo apt install python3-venv

Go to the directory you want to create the Virtual Environment and enter the following command.
python3 -m venv .venv

As you can see, it creates a hidden directory.

Now just need to go inside and activate it.

Now anything you do stays there.
You can install anything, run anything without damaging the room.

To get out of there, just enter deactivate.

It's better to install something like Ipython inside a Virtual Environment which is an application which helps to run a Python code line by line.

Install Ipython
sudo apt install python3-pip
pip3 install ipython

Now we can just enter ipython and go the prompt to execute lines of code and type exit when its done.









Accessing from a Windows Machine

Most of the time I like to work directly in the Ubuntu machine but in cases where we need to work in Windows machines yet still need Ubuntu machine to compile and develop code, we can use Remote-SSH extension to let VS Code in Windows machine to access VS Code in Ubuntu machine and run code there.

For that we need to install SSH server on Ubuntu machine

sudo apt install openssh-server

Then you can SSH using to the Ubuntu machine from VS Code using the installed extension and work just like you are in your VM. Since this is based on SSH, you can use any machine to log in to this VM if the network allows it. You can also run commands in Terminal in VS Code just like you are in the actual VM.


No comments:

Post a Comment