Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Markdown
### With necessary permissions
```console
$ module load itm-python
$ python3 -m pip install --upgrade pip
```

### Without necessary permissions
This solution is not recommended, but may be needed under certain circumstances, such as when the user does not have permissions. ```console
$ module load itm-python
$ python3 -m pip install --upgrade pip --user
```
In that case it may be needed to add a local site-packages directory to $PATH:
```console
$ PATH=$HOME/.local/bin:$PATH
```

 Virtual Environment

At its core, the main purpose of Python virtual environments is to create an isolated environment for Python projects. This means that each project can have its own dependencies, regardless of what dependencies every other project has. The great advantage is that there is no limit to the number of environments that can be created as it is just a directory with a few scripts that handle system package isolation.

As shown in the previous section, there are at least two different locations where Python packages can be installed on the system. This can pose risks such as name shadowing or even suppression of certain packages from the kernel to the system. Most of the time, nothing like this happens, but even so, using a Python virtual environment is also considered good practice. This tutorial assumes usage of at least Python 3.6, therefore it should already have the venv module from the standard library installed.

Markdown
### Creating a Virtual Python Environment
```console
# Python 3
$ python3 -m venv env-name
```
And that's just it. It is important to use the __venv__ module as others are deprecated. The name of the environment can be anything as it is just a directory name, however it is good practice to use names like __*env*__ or __*venv*__ or expand with these names.

### Activate The Virtual Environment
To activate the environment just created, navigate to the location where it was created, if not already there, and execute the following command:
```console
$ source env-name/bin/activate
(env-name): $
```
As a result of activation, the currently used shell should explicitly show the name of the environment being activated on the command line.