Skip to content

Create a virtual environment

Björn Ludwig edited this page Nov 22, 2019 · 2 revisions

When working with Python we should always work in so-called virtual environments, in which our project specific dependencies are satisfied without polluting or breaking other projects' dependencies and to avoid breaking all our dependencies in case of an update of our Python distribution.

If you are not familiar with Python virtual environments you can get the motivation and an insight into the mechanism in the official docs. On this wiki page we provide links and examples to create a virtual environment both with Mini-/Anaconda or alternatively with pip.

Create a virtual environment with Mini-/Anaconda

For easy environment creation we provide an environment.yml file in the root of our repository. With this file you can create a virtual environment on your local machine as described in the official docs of Anaconda.

It boils down to navigating to your repository's folder and executing

$ conda env create -f environment.yml

Afterwards you can work with your environment on the command line by issuing

$ conda activate Met4FoF_Code

Create a virtual environment for pip

For easy environment creation with Python built-in tools we provide a requirements.txt file in the root of our repository. With this file you can create a virtual environment on your local machine as described in the official docs of Python itself.

It boils down to navigating to any folder, in which you want to create a subfolder with the name Met4FoF_Code for the virtual environment and executing

$ python3 -m venv Met4FoF_Code

Then activate the fresh environment as described in the official docs,

$ source Met4FoF_Code/bin/activate

which will most likely display the environment name in front of the shell and install the project's dependencies with

(Met4FoF_Code) $ pip install -r /PATH/TO/YOUR/CLONE/requirements.txt

Proceed with the next step

Ready for CLI executions