Setting Up Python Workspace with Virtualenv and VS Code

Jan 01, 2022

#python #virtualenv #vscode


Install python

Just type python on your terminal (Linux) or cmd prompt (Windows)

❯ python
Python 3.10.1 (main, Dec 18 2021, 23:53:45) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

If it gives error, then install python first https://python.org/downloads/

virtualenv

python -m pip install virtualenv

set up a workspace

mkdir workspace
cd workspace
python -m virtualenv .venv

Ativate virtualenv For Linux

source .venv/bin/activate

For Windows

.venv\Scripts\activate.bat

Installed packages can be seen by pip list

pip list
Package    Version
---------- -------
pip        21.3.1
setuptools 59.5.0
wheel      0.37.0

Pip

pip is package manager used for installing python packages

pip install numpy matplotlib pandas jupyter

Jupyter notebook

jupyter notebook

VSCode

Install VSCode from https://code.visualstudio.com/

Create a create.py file

touch hello.py

Lanuch vscode from the terminal

code .

Vscode plugins

Type Ctrl+Shift+X which will open a side pannel and search this plugins and install to your machine

Python
Jupyter
Code Runner

Now VScode automatically detect the virtualenv, if not, click on left bottom panel to select the correct python env.

VSCode Enjoy coding :)