0% found this document useful (0 votes)
14 views

Practical 1 Python Virtual Environments and Using JupyterLab

Uploaded by

black hello
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Practical 1 Python Virtual Environments and Using JupyterLab

Uploaded by

black hello
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1 of 5

BMCS2013 Data Engineering

Practical 1 Python venv and Using JupyterLab


Python virtual environments create a self-contained and isolated environment for different
Python projects. This would enable you to install a specific version of a module on a per
project basis which will not affect your other Python projects.

1. Launch the Ubuntu-22.04-de distro:


In PowerShell (run as administrator), launch the distro for this course:
PS C:\Users\TARUMT> wsl ~
hduser@PC25:~$

~~~ As the user student ~~~


2. Create a virtual environment
2.1. Create a project folder (e.g., de-prj)

$ mkdir de-prj

2.2. Create a virtual environment for your project (e.g., de-venv):


$ python3 -m venv de-prj/de-venv
$ de-prj/de-venv/bin/python -m pip install -U --quiet pip
wheel setuptools
$ de-prj/de-venv/bin/python -m pip install -U --quiet
ipykernel
$ de-prj/de-venv/bin/python -m ipykernel install --user
--name "de-venv" --display-name "de-venv"

3. Using JupyterLab
3.1. Run the JupyterLab service:
$ jupyter lab
2 of 5

3.2. Access JupyterLab

From the output shown in your terminal, copy and paste one of the URLs (see
diagram in previous page) in a browser.

3.3. To create a jupyter notebook based on your virtual environment

Under Notebook, just click on


the kernel with your virtual
environment name.

3.4. To close a jupyter notebook and shut down the kernel (i.e., venv)

With the jupyter notebook as


the active tab, click File and
then select Close and Shut
Down Notebook…

3.5. To logout from JupyterLab,


3 of 5

Click File and then select


Log Out
4 of 5

3.6. To shut down the jupyterlab server,

3.6.1. Go to the terminal where you ran the command to start


JupyterLab (i.e. in Step 3.1)

3.6.2. Press <Ctrl><C> and type ‘y’ to confirm that you want to shut
down the server.

3.7. To delete any unwanted venv:


Syntax: jupyter kernelspec uninstall unwanted-kernel
Example:
student@PC25:~$ jupyter kernelspec uninstall alpha-
venv

4. Installing python packages in your virtual environment


4.1. Activate the virtual environment
$ source de-prj/de-venv/bin/activate

4.2. Update the python build packages


(de-venv) $ pip install -U pip wheel setuptools

4.3. Install packages


(de-venv) $ pip install numpy pandas pyspark

4.4. Deactivate the virtual environment


Once you no longer need to work in the environment, you may deactivate the
environment to return to your normal shell.
5 of 5

(de-venv) $ deactivate

You might also like