Creating environments and install packages

It is important to understand, that you are always “residing” somewhere in some folder. This will in particular important to make sure that you find your scripts, notebooks and the working data, which ideally reside under the same directory hierarchy.

In order to be well organised throughout the course, please create a working folder/directory, where you will put your scripts and data files for the lab sessions and homeworks. On Windows you have your local user folder, typically C:\Users\Alexander. Open with the Windows File Explorer and create a new folder in this folder, with the name geopython2022.

BEWARE:

Make sure you navigate explicitly into your correct working folder “geopython2022”. As we will always start or environment from the command line, here are two very simple practical steps to navigate on the commandline.

Open the Anaconda/conda command prompt from the Start menu, and type the commands shown below.

c:
cd C:\Users\Alexander\geopython

You can see which files are inside this folder by using the dir command. (On Mac and Linux it is ls) and it will print information and files of your current folder.

c:
cd C:\Users\Alexander\geopython2022

dir

... output below

Volume in drive C is Windows
Volume Serial Number is 5E4C-FED5

Directory of C:\Users\Alexander\geopython2022

29.09.2021  15:00    <DIR>          .
29.09.2021  15:00    <DIR>          ..

conda basically represents a typical Python virtualenv command. You can create a several distinct environments, with different Python version, and with different packages to be installed. This will come in very handy to try out new libraries/packages/tools, without breaking you working installation. How to use the conda command?

https://docs.conda.io/projects/conda/en/latest/user-guide/cheatsheet.html

We want to use a modern Python version 3.8, but some packages might not be fully available or tested in Python 3.9. Here it becomes obvious how practical virtual environments can be. They help you to keep various Python versions around without messing up your system, and at the same time, keep several working environments with different, possibly conflicting versions of different Python packages.

There are two main ways of creating a conda environment.

The more professional/reproducible way is to use a so called environment.yml file. In the file the environment name, the package channels, Python version and all desired packages are declared. This way, you should be able to install the same environment in different computers, therfore improving the reliability of having the same packages etc installed. You can even go so far as to specify the exact package version.

Make sure you are using the correct folder on the University computers. In the Windows File Explorer, go via this PC, c:\Users to your account name folder.

Note

Now, please download the prepared environment.yml file and save it to your newly created working folder. You might need to “Right-click” and use “Save as”.

To check, in the commandline window (Anaconda prompt) navigate to your working folder again and list the contents of the folder with dir:

(C:\dev\conda3) c:

(C:\dev\conda3) cd C:\Users\Alexander\geopython2022

(C:\dev\conda3) dir

... output below

Volume in drive C is Windows
Volume Serial Number is 5E4C-FED5

Directory of C:\Users\Alexander\geopython2022

29.10.2021  15:00    <DIR>          .
29.10.2021  15:00    <DIR>          ..
29.10.2021  08:51 AM            693 environment.yml

You should see the newly downloaded file in your folder. Now let’s install the enviroment with conda:

(C:\dev\conda3) conda env create -f environment.yml

This will take some time.

In the next steps we will verify the installation and test that everything works in our new geopython2022 conda Python environment and configure Jupyter Notebooks.