{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Use Conda with the fish shell\n", "\n", "Long time ago I switched from the default Ubuntu shell (bash I guess) to [fish shell](http://fishshell.com). I'm still far from being an fish shell power user, but I like the out of the box experince with auto-completion etc. Anyways, today I wanted to play with another technology new to me, called [conda](http://conda.pydata.org/docs). Conda is an package manager for installing and managing software packages (you can read in detail about it on the [conda](http://conda.pydata.org/docs) page). \n", "\n", "## Installing Conda\n", "\n", "Conda comes in two versions:\n", "\n", "1. Anaconda: This is the main package which includes a bunch of existing Python packages \n", "2. Miniconda: Does not include any additonal packages, just the conda package manager. \n", "\n", "The conda manual contains an overview of both [here](http://conda.pydata.org/docs/download.html). I chose to use the light-weight option, namely miniconda. On Linux the installer is basically a shell-script which will self-extract into your home directory in my case `~/miniconda3` (or whereever you chose to put it). \n", "\n", "```\n", "cd ~/Downloads\n", "wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh\n", "bash Miniconda3-latest-Linux-x86_64.sh\n", "```\n", "\n", "This will install the Linux x86 64 bit version of miniconda for Python 3. \n", "\n", "During the installation you can choose to let the installer modify your `~/.bashrc` to add `~/miniconda3/bin` to your `PATH` environment variable, such that you can run the conda commands like any other system level command (just one small cavat is that miniconda also ships with its own version of Python, so this will also take precedense over the one system installed one). That didn't work well for me, because the miniconda version of Python has some packages removed (e.g. [test](https://docs.python.org/3/library/test.html) which some Python packages rely on even though it is meant for internal testing). Note that fish does not use `~/.bashrc`. Instead fish uses `~/.config/fish/config.fish`, so to set the `PATH` environmenbt variable I added:\n", "\n", "```\n", "set -x CONDA_PATH $HOME/miniconda3/bin\n", "\n", "function condaon\n", " set -x PATH $CONDA_PATH $PATH\n", " echo \"Hello Conda (adding\" $CONDA_PATH \"to PATH)\"\n", "end\n", "```\n", "\n", "Now I can write `condaon` in my terminal, which will add the miniconda directory to my path.\n", "\n", "Fish provides `set` to manipulate environment vaiables. The first arguement `-x` will export the enviroment variable to child processes. The second arguement is the name of the environment varaible we want to set (in this case `PATH`). Finally we provide a space seperated list of value to use. For more detailed documentation use `man set`.\n", "\n", "Open a new fish shell and try typing `conda help` and you should be ready to go.\n", "\n", "## Using Conda environments (new way)\n", "\n", "To use Conda's environment activation/deactivation in the fish shell source the file from `~/miniconda3/etc/fish/conf.d/conda.fish` to automatically load the needed functions when a new fish shell is started. This is done by adding `source ~/miniconda3/etc/fish/conf.d/conda.fish` to `config.fish`. \n", "\n", "As a small note, I normally have my config files stored in Dropbox so when configuring a new machine I just need to create the symlinks. That works pretty well.\n", "\n", "Note you need fish shell version +2.2.x. Check your version with `fish --version`, if you are using Ubuntu you can upgrade to a newer version with the [Fish shell maintainers PPA](https://launchpad.net/~fish-shell/+archive/ubuntu/release-2).\n", "\n", "## Using Conda environments (old way)\n", "\n", "Currently Conda's environment activation/deactivation does not fully support the fish shell. There is an open [pull-request](https://github.com/conda/conda/pull/545) which adds support though. So when it gets merged we should be able to do a `conda update conda` and use the provided script. \n", "\n", "Until then we can use the script provided in the pull-request:\n", "\n", "```\n", "cd ~/.config/fish\n", "wget https://raw.githubusercontent.com/aldanor/conda/fish/bin/conda.fish\n", "```\n", "\n", "Source the file from `~/.config/fish/config.fish` to automatically load the needed functions when a new fish shell is started. This is done by adding `source ~/.config/fish/conda.fish` to `config.fish`. \n", "\n", "As a small note, I normally have my config files stored in Dropbox so when configuring a new machine I just need to create the symlinks. That works pretty well.\n", "\n", "Note you need fish shell version +2.2.x. Check your version with `fish --version`, if you are using Ubuntu you can upgrade to a newer version with the [Fish shell maintainers PPA](https://launchpad.net/~fish-shell/+archive/ubuntu/release-2).\n", "\n", "## Creating a new environment\n", "\n", "If you haven't used Conda before, you can try this just to get started :) It will install the newest version of the [jupyter](https://jupyter.org/) notebook in a Conda environment called `jupyter`.\n", "\n", "```\n", "conda create --name jupyter jupyter\n", "```\n", "\n", "Activate the environment:\n", "\n", "```\n", "conda activate jupyter\n", "```\n", "\n", "Launch the Jupyter notebook:\n", "\n", "```\n", "jupyter notebook\n", "```\n", "\n", "Deactivate the environment again:\n", "\n", "```\n", "conda deactivate\n", "```\n", "\n", "Have fun :)" ] } ], "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.1" } }, "nbformat": 4, "nbformat_minor": 1 }