vvoutilainen conda environments

Ville Voutilainen
2021-09-16

* Views expressed are those of the presenter.
Presentation tested to work in Chrome.

In this presentation


  • Introduction to Anaconda with Python and R.

  • Installing and using custom conda environments.

More about me

vvoutilainen.github.io

@VilleEcon

Anaconda for Python and R

  • Anaconda is a popular data science platform for Python and R.
  • It comes pre-installed with over 1000 packages and libraries.
  • Python, R, and their packages are used within environments.
  • Environments are managed with conda, Anaconda's packages manager.

What can we do with the environments?

  • Run Python in VSCode or Jupyter Lab.
  • Run R in RStudio or Jupyter Lab.
  • Call R code from a Python instance.
  • Use typical Python data science packages such as pandas and scikit learn.
  • Use typical R data science packages such as tidyverse.
  • Fetch economic time series from public APIs using rjsdmx.

Creating environments

base environment can be used out-of-box after installation. In Anaconda prompt:

						
							conda activate base
						
					

We want to install additional dev environment.

Our environment dev2018 contains packages for Python based work, with occasional estimations in R:

						
							conda create --name dev2018 anaconda python=3.6
							r=3.6.0 rest_of_packages
						
					

Creating environments, condt.

To use Jupyter, we need to register kernels for both new Python and R executables:

						
						conda activate dev2018
						python -m ipykernel install --user --name dev2018_py --display-name "dev2018_py"
						R
						IRkernel::installspec(name='dev2018_r', displayname='dev2018_r')
						quit()
						
					

Installing packages

conda's benefit comes from dependency management.

Always try installing first with conda! For example:

						
						conda activate dev2018
						conda install pckg_name
						
					

If installing via conda fails, one can try typical solutions:

						
						# Python
						conda activate dev2018
						pip install pckg_name
						# R
						install.packages("pckg_name")
						
					

Thank you!

@VilleEcon

vvoutilainen.github.io

References: