Setting Up a Python Virtual Environment on Sophia
Default Python Version
The default Python on Sophia is located at /usr/bin/python
with version 3.9.18.
Creating a Virtual Environment
Creating a virtual environment allows you to manage dependencies for your Python projects independently. This is particularly useful when working on multiple projects with different dependencies or versions of packages. Follow these steps to set up a virtual environment on Sophia:
-
Create a Virtual Environment:
Replacemyenv
with your preferred name for the virtual environment. This will create a directory with the specified name containing the virtual environment. -
Activate the Virtual Environment:
After activation, your command prompt will change to indicate the virtual environment is active. -
Upgrade
pip
:While this step is optional, it is a good habit to use the latest version of
pip
: -
Install Packages: Use
Replacepip
to install necessary packages:package_name
with the name of the package you want to install.
Creating a Jupyter Kernel
If you would like to use your Python virtual environment on JupyterHub, you will need to create a Jupyter kernel for it.
-
Install
ipykernel
: Ensureipykernel
is installed in your virtual environment: -
Create a Jupyter Kernel:
Replacemyenv
with the name of your virtual environment and"Jupyter (myenv)"
with the display name you want for the kernel in JupyterHub.