{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Conda and pip - managing environments\n", "\n", "**Environment:** \"the world around you\". In the Python context, a way to define all the tools and libraries that will be loaded when code is run, in a manner that makes it possible to reload them later in a predictable and reproducible fashion. This requires being able to both describe the necessary packages and to install/remove them.\n", "\n", "**Conda:** a tool to install packages and to manage environments. Open source, developed by Anaconda (a company). It can manage not only Python packages but also R, C tools and more. The [canonical conda docs](https://conda.io/docs/user-guide/tasks/manage-environments.html).\n", "\n", "**Pip:** the Python packaging tool, it only installs/removes Python packages, hosted at the [Python Package Index (PyPI)](https://pypi.python.org/pypi).\n", "\n", "\n", "## We will mostly use Conda\n", "\n", "For managing our environments and dependencies. But we may need to occasinally install packages with `pip` if they aren't available via Conda.\n", "\n", "One important note: `conda create` and `conda env create` are very similar, but not identical (this is for historical reasons, they are being now merged). To create a new environment based on a few packages specified at the command line, use e.g.:\n", "\n", " conda create -n myenv python=3.6 notebook pandas\n", " \n", "but to create an env based on an `environment.yml` file, use:\n", "\n", " conda env create -f environment.yml\n", " \n", "You can bootstrap the creation of the `environment.yml` file from an existing environment by using:\n", "\n", " conda env export > environment.yml\n", " \n", "A key feature of using `environment.yml` is that you can specify within it not only packages installed with Conda, but also with pip.\n", "\n", "Here's an example of a simple `environment.yml` file:\n", "\n", "```\n", "name: example-environment\n", "\n", "dependencies:\n", " - python==3.4\n", " - numpy\n", " - toolz\n", " - matplotlib\n", " - dill\n", " - pandas\n", " - partd\n", " - bokeh\n", " - pip:\n", " - git+https://github.com/blaze/dask.git#egg=dask[complete]\n", " - jupyterlab\n", "```\n", "\n", "To see your environments: `conda info -e`.\n", "\n", "To remove an environment: `conda remove -n example-environment --all`." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }