Setup Jupyter Notebook in VS Code
We have implemented a single virtual environment for all the projects/code that we will be
working with, as the scope of our course is limited to using only the said libraries with the
same version applicable to all of our projects.
This is our folder structure (you will have your own):
.
└── d/
└── tech/
└── micro-concepts/
└── ai-ml-iitk/
└── projects/
├── venv/
├── project-name-1/
├── project-name-2/
├── project-name-3/
├── project-name-4/
└── ....and so on
IMPORTANT NOTE
For libraries like TensorFlow to work, we have globally installed Python 3.10.11.
For ease of installation, I recommend to uninstall any other python version which is
already installed & re-install the above version from here:
Windows 32 bit
Windows 64 bit
I. Install Extension
Go to extension tab in VS Code & install this Extension
II. Create Virtual Environment
a) Open terminal
Click "New Terminal"
a) Point the terminal to the desired folder
cd "<LOCATION_OF_PARENT_FOLDER_WHERE_VENV_TO_BE_LOADED"
create a folder "projects" anywhere & copy it's path & then use that path inside the
quotes
b) Create a virtual environment
python -m venv <VIRTUAL_ENV_NAME>
NOTE (Ignore if Python 3.10.11 is installed globally)
If you have a different version(s) installed globally apart from 3.10.11 on your local
machine, then you will have to use Python 3.10.11 for this venv (read important note):
<LOCATION_OF_PYTHON_EXE> -m venv venv
where <LOCATION_OF_PYTHON_EXE> can be:
C:\Users\ragha\AppData\Local\Programs\Python\Python310\python.exe
c) Activate the virtual environment
./venv/Scripts/activate
d) Install dependencies
pip install numpy scipy matplotlib pandas scikit-learn seaborn tensorflow
keras ipykernel
Your virtual environment is setup successfully.
III. Create Jupyter Kernel
a) Register virtual environment by creating a new kernel
python -m ipykernel install --user --name=common-aiml-venv --display-name
"Common env for AI,ML,DL"
replace "common-aiml-venv",
replace "Common env for AI,ML,DL", as per your own choice
b) Restart VS Code
Restart the VS Code so that the newly created kernel can be picked up by the system.
IV. Create project folder & files
a) Create a project folder under the parent directory "projects"
mkdir hello-world
cd hello-world
b) Create the Jupyter notebook file
Use the interactive user-interface to create a file named "hello-world.ipynb" inside the folder
"hello-world"
c) Select kernel inside the file
d) Choose "Jupyter Kernel"
e) Choose the name of the kernel
V. Test package installation
Click "+ Code" in the Jupyter Notebook File:
& paste the following codes (mentioned below), after pasting click "Run":
a) NumPy (code given by IITK)
import numpy as np
import matplotlib.pyplot as plt
blockLength = 10000000;
nbins = 1000;
a = np.random.normal(0.0, 1.0, blockLength);
plt.figure()
plt.hist(a,bins=nbins,density=True);
plt.suptitle('Gaussian PDF')
plt.xlabel('x')
plt.ylabel('$f_X$(x)')
b) Tensorflow
import tensorflow as tf
# Print TensorFlow version
print("TensorFlow version:", tf.__version__)
# Check if GPU is available
print("Num GPUs Available:", len(tf.config.list_physical_devices('GPU')))
# Run a simple computation
a = tf.constant([[1.0, 2.0], [3.0, 4.0]])
b = tf.constant([[1.0, 1.0], [0.0, 1.0]])
c = tf.matmul(a, b)
print("Matrix multiplication result:")
print(c)
c) Keras
import keras
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
# Generate dummy data
x_train = np.random.rand(100, 10)
y_train = np.random.randint(0, 2, size=(100,))
# Define a simple model
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=(10,)))
model.add(Dense(1, activation='sigmoid'))
# Compile the model
model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])
# Print model summary
model.summary()
# Train the model on dummy data
model.fit(x_train, y_train, epochs=3, batch_size=10)
You will know if the code works or not.