Create a Python Environment


To download and work with satellite data, several packages are required that are not part of the standard Anaconda installation. In general, however, it is NOT a good idea to install additional packages into the “base” environment (the version of Python and the hundreds of most commonly used packages that are installed with Anaconda) because conflicts can arise. Instead, users should create an environment that contains a specific version of Python and the required packages for a specific application - in this case, working with satellite data.

An environment is isolated from the base environment, so its packages don’t conflict with those in the base environment. Multiple different environments can be created, for use with different applications or testing. An added benefit when sharing Python scripts is that the environment configuration file can be distributed along with the script, so users can run the script with the same Python configuration used to write it.

The instructions below will install Python and a set of packages needed for working with satellite data into a new environment called “satellite_aerosol”, using an environment.yml file and the conda package manager.


1. Ensure Anaconda is installed on your machine

In order to create a Python environment using conda, you must have Anaconda installed on your laptop or in your home directory if you are using a Linux server. The most common reason for getting an error message in Step 5 is because users think they have Anaconda installed, but they actually don't.

If you need to install Anaconda, follow these instructions before moving on to Step 2.


2. Download the “satellite_aerosol.yml” environment configuration file

The "satellite_aerosol.yml" file is an environment configuration file in YAML Ain't Markup Language format. It was distributed in a .zip file along with Python code file(s) for your training course.

Ensure that you downloaded the .zip file to the machine on which you have Anaconda installed, and you extracted the contents of the .zip file and saved them in a convenient directory, such as the Desktop.


3. Open the Anaconda Powershell Prompt (Windows) or terminal (MacOS/Linux)

Windows: go to Start menuAnaconda3Anaconda Powershell Prompt

MacOS: open the Terminal

Linux: open a terminal


This is the directory where the files were extracted/saved in Step 2. For example, if the .yml file is in the Desktop, the command typed into the terminal/prompt may look like:

Windows:

cd C:\Users\Jane.Doe\Desktop

MacOS:

cd ~/Desktop

Linux:

cd /home/jane.doe/Desktop


5. Install the environment

Type the following command (or copy and paste) into the terminal/prompt and press Enter:

conda env create -f satellite_aerosol.yml


The installation will take several minutes to complete (~5-15 min). You can do other work while the environment is installing, but don’t close the terminal/prompt window! During the installation, if you see a warning to install an updated version of conda, you should be able to ignore it.

After the environment is finished installing, you may exit the terminal/prompt.


6. Activate the environment in Jupyter Notebook

Switching or moving between environments is called “activating” the environment. For our training courses, we run the Python code tutorials in Jupyter Notebook.

In order to activate environments in Jupyter Notebook, a package called nb_conda_kernels must be installed.


Optional: Activate the environment from the command line

Depending on your needs and level of expertise, you may want to run Python scripts (.py files) from the commmand line.

To activate the environment from the command line, open the Anaconda Powershell Prompt (Windows) or terminal (MacOS/Linux), then type the following command and press Enter:

conda activate satellite_aerosol


You should see the name of the environment in parentheses (satellite_aerosol) to the left of the cursor on the command line.


To list the packages in the environment, type the following command and press Enter:

conda list


In the active environment, run code or scripts from the command line as you normally would. For example, to run the file called "filename.py", you would type the following and press Enter:

python filename.py


To exit the environment and return to the base environment, type the following command and press Enter:

conda deactivate