Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Conda is a tool commonly used to manage dependencies and projects. You can create a conda environment and install the packages that you need for each project. If you make changes to one of your conda environments, your other environments are not affected. For more information, please refer to the Conda User Guide.

The following examples illustrate common conda tasks using JupyterHub on IDAS. 


Set up

Create a conda environment with Python 3.8 

  • Now we can create a conda environment with Python 3.8, which is a different version from the default version in IDAS. In this example, we name the environment "py38".

    conda create -n py38 python=3.8

    When prompted "Proceed ([y]/n)?", press "y" to proceed.

  • Once this conda environment is created, we can activate it.

    conda activate py38
  • The command prompt in your Terminal will change to indicate the active environment.

    (py38) hawkid@jupyter-notebook-research-hawkid:~$
  • Next, we create a kernel in order to use Jupyter Notebook with this conda environment. Install the IPython kernel:

    conda install ipykernel

    When prompted "Proceed ([y]/n)?", press "y" to proceed.

  • Now install a kernel in this environment:

    python -m ipykernel install --user --name py38 --display-name "Python 3.8"

    The value for "--name" is used by Jupyter internally. Any existing kernel with the same "--name" value will be overwritten. The "--display-name" will be displayed in the Notebook menu.

  • Reload the IDAS home page. Under New / Notebook, an option called "Python 3.8" will now be available.



  • To install Python packages in this conda environment, first start a new Jupyter Notebook by selecting New / Python 3.8.
  • In a cell in this new notebook, use the %conda magic that is built into IPython to install packages within the current kernel. For example, install the "pandas" package:
  • Then we can load and use the package as usual:
  • Once we are finished working with the current conda environment, we can deactivate it by typing the following in Terminal:

    conda deactivate


    Or, to return to the "base" environment, type (with no environment specified) in Terminal:

    conda activate

Other useful conda commands 

The following commands may be useful to manage conda environments. Type the following commands in Terminal. For more information, please refer to the "Managing environments" section in the Conda User Guide.

  • List all of your environments. In the output, your current environment will be marked with an asterisk (*).

    conda info --envs

    or

    conda env list
  • View a list of packages installed in an environment:
    • If the environment is not activated, type (without the angle brackets):

      conda list -n <environment-name>
    • If the environment was already activated with "conda activate" earlier, type (without the angle brackets):

      conda list
  • To see if a specific package is installed in an environment, type (without the angle brackets):

    conda list -n <environment-name> <package-name>
  • Remove an environment:

    conda remove --name <environment-name> --all

    or

    conda env remove --name <environment-name>

Using pip in a conda environment

Please note that issues may arise when using pip and conda together. The "Using pip in an environment" section in the Conda User Guide outlines best practices for using pip in a conda environment.

  • No labels