2024-heraklion-ODD/exercises/exercises2023/Exercise 1 Virtual Environments.md

1.4 KiB

Exercise 1: Virtual Environments

Goal

Create a virtual environment + install a package + see that that package was installed only in environment

Tasks

We will use venv as our environment manager - while commands might differ, the principles apply to all other package managers as well.

  1. Check which Python you are currently using, and which packages are installed. Also check which folders are in the folder you are installing the environment into.
  2. Create and activate a new environment.
  3. Check again which Python you are using and which packages are installed - are they different?
  4. Install a specific version of a package using pip e.g. pandas=1.5.3
  5. See that dependencies are also installed (more packages than only pandas appear)
  6. Deactivate and delete the environment

Commands in case you get stuck (not in correct order):

% investigate Python and packages
> which python
> pip freeze
> pip install <package-name>
> pip install <package-name>==0.0.1

% create an environment option 1 (create folder called venv_folder for files related to virtual environment, feel free to change the name)
> cd <path-to-project_folder>
> mkdir venv_folder
> python3 -m venv venv_folder
> source venv_folder/bin/activate

% create an environment option 2
> python3 -m venv <path-to-folder-for-venv>
> source <path-to-folder-for-venv>/bin/activate

% deactivate and delete a venv environment
> deactivate
> rm -rf venv_folder