Introduction to eclimate jupyterLab

Pangeo notebook

Pangeo is a community platform for Big Data geoscience that promotes open, reproducible, and scalable science.

The Pangeo software ecosystem involves open source tools such as xarray, iris, dask, jupyter, and many other packages. Make sure you select pangeo notebook as shown on the figure below to get all the necessary python packages.

Activate pangeo conda environment

From a JupyterLab Terminal, you would need to activate the pangeo environment:

source activate pangeo

Stop/Restart your server

Stop your server

We recommend to stop your server when you no longer need it (typically at the end of each day).

Your server can be stopped from the “Hub control panel”:

Hub control panel

Then stop:

Stop server

Note

Stop server versus stop kernel

Stopping the kernel(s) of jupyter notebooks only apply to your notebooks, not to your “jupyterLab”.

Restart your server

  • To start your server:

Start server

  • Often it needs to be launched:

Server not launched

  • That’s what you get when it starts

Server starting

More on conda

Here you will find a very short summary of Introduction to Conda for (Data) Scientists.

Conda is an open source package and environment management system that runs on Windows, Mac OS and Linux.

  • Conda can quickly install, run, and update packages and their dependencies.

  • Conda can create, save, load, and switch between project specific software environments on your local computer.

  • Conda can package and distribute software for any language such as R, Ruby, Lua, Scala, Java, JavaScript, C, C++, FORTRAN.

Conda as a package manager helps you find and install packages. If you need a package that requires a different version of Python, you do not need to switch to a different environment manager, because Conda is also an environment manager. With just a few commands, you can set up a totally separate environment to run that different version of Python, while continuing to run your usual version of Python in your normal environment.

Create/update conda environment

Note

Avoid installing new packages in existing conda environments

Conda has a default environment called base that include a Python installation and some core system libraries and dependencies of Conda. In the eclimate JupyerLab, we also provide additional conda environment such as pangeo. It is a “best practice” to avoid installing additional packages into these software environments. Additional packages needed for a new project should always be installed into a newly created Conda environment.

Creating environments

To create a new environment for Python development using conda you can use the conda create command.

$ conda create --name python3-env python pip

Note

Always install pip in your Python environments

Pip, the default Python package manager, is often already installed on most operating systems (where it is used to manage any packages need by the OS Python). Pip is also included in the Miniconda installer. Including pip as an explicit dependency in your Conda environment avoids difficult to debug issues that can arise when installing packages into environments using some other pip installed outside your environment.

It is a good idea to give your environment a meaningful name in order to help yourself remember the purpose of the environment. While naming things can be difficult, $PROJECT_NAME-env is a good convention to follow.

The command above will create a new Conda environment called “python3” and install the most recent version of Python. If you wish, you can specify a particular version of packages for conda to install when creating the environment.

$ conda create --name python36-env python=3.6 pip=20.0

Note

Always specify a version number for each package you wish to install

In order to make your results more reproducible and to make it easier for research colleagues to recreate your Conda environments on their machines it is a “best practice” to always explicitly specify the version number for each package that you install into an environment.

Create new environment and install multiple packages

You can create a Conda environment and install multiple packages by simply listing the packages that you wish to install.

$ conda create --name basic-scipy-env ipython=7.13 matplotlib=3.1 numpy=1.18 pip=20.0 scipy=1.4

When conda installs a package into an environment it also installs any required dependencies. For example, even though Python is not listed as a packaged to install into the basic-scipy-env environment above, conda will still install Python into the environment because it is a required dependency of at least one of the listed packages.

Activating an existing environment

Activating environments is essential to making the software in environments work well (or sometimes at all!). Activation of an environment does two things.

  1. Adds entries to PATH for the environment.

  2. Runs any activation scripts that the environment may contain.

Step 2 is particularly important as activation scripts are how packages can set arbitrary environment variables that may be necessary for their operation. Aou activate the basic-scipy-env environment by name using the activate command.

$ source activate basic-scipy-env

You can see that an environment has been activated because the shell prompt will now include the name of the active environment.

 (basic-scipy-env) $

Deactivate the current environment

To deactivate the currently active environment use the deactivate command as follows.

 (basic-scipy-env) $ source deactivate

You can see that an environment has been deactivated because the shell prompt will no longer include the name of the previously active environment.

Note

Returning to the base environment

To simply return to the base Conda environment, it’s better to call source activate with no environment specified, rather than to use deactivate. If you run source deactivate from your base environment, you may lose the ability to run conda commands at all. Don’t worry if you encounter this undesirable state! Just start a new shell.

Installing a package into an existing environment

You can install a package into an existing environment using the conda install command. This command accepts a list of package specifications (i.e., numpy=1.18) and installs a set of packages consistent with those specifications and compatible with the underlying environment. If full compatibility cannot be assured, an error is reported and the environment is not changed.

By default the conda install command will install packages into the current, active environment. The following would activate the basic-scipy-env we created above and install Numba, an open source JIT compiler that translates a subset of Python and NumPy code into fast machine code, into the active environment.

$ source activate basic-scipy-env
$ conda install numba

As was the case when listing packages to install when using the conda create command, if version numbers are not explicitly provided, Conda will attempt to install the newest versions of any requested packages. To accomplish this, Conda may need to update some packages that are already installed or install additional packages. It is always a good idea to explicitly provide version numbers when installing packages with the conda install command. For example, the following would install a particular version of Scikit-Learn, into the current, active environment.

$ conda install scikit-learn=0.22

Note

Freezing installed packages

To prevent existing packages from being updating when using the conda install command, you can use the --freeze-installed option. This may force Conda to install older versions of the requested packages in order to maintain compatibility with previously installed packages. Using the --freeze-installed option does not prevent additional dependency packages from being installed.

Getting some information on existing environments

Listing existing environments

Now that you have created a number of Conda environments on your local machine you have probably forgotten the names of all of the environments and exactly where they live. Fortunately, there is a conda command to list all of your existing environments together with their locations.

$ conda env list

Listing the contents of an environment

In addition to forgetting names and locations of Conda environments, at some point you will probably forget exactly what has been installed in a particular Conda environment. Again, there is a conda command for listing the contents on an environment. To list the contents of the basic-scipy-env that you created above, run the following command.

$ conda list --name basic-conda-env

Deleting entire environments

Occasionally, you will want to delete an entire environment. Perhaps you were experimenting with conda commands and you created an environment you have no intention of using; perhaps you no longer need an existing environment and just want to get rid of cruft on your machine. Whatever the reason, the command to delete an environment is the following.

$ conda remove --name my-first-conda-env --all