Creating new Conda Environment and importing into Jupyter on MacOSX

1 minute read

Creating new Conda Environment

So to start with let me put the documentation page, which is pretty straight forward and you may refer there for further information

https://conda.io/docs/user-guide/tasks/manage-environments.html

So it is a good practice to start with a fresh environment for your fresh project. You can install only the dependencies you need and later export them if you need to share your project in the future or replicate on another machine. And frankly it is pretty easy to do that. Lets assume that you have conda installed on your machine. Then what we need to do is create the environment. You can specify python version like python=3.4. After creating we can activate the environment and install manually whatever we need.

conda create -n <new_env_name> python
source activate <new_env_name>
conda install pytorch torchvision -c soumith
source deactivate

You can later save the environment and create a new environment using the specs. Or(last line below) you can install the specs into an existing environment.

conda list --explicit > spec-file.txt
conda create --name <new_env_name> --file spec-file.txt
conda install --name <env_name> --file spec-file.txt

You can also export the environment.yaml

source activate <new_env_name>
conda env export > environment.yml
source deactivate

If you are working with jupyter notebooks, the easiest way to export your environment into jupyter is installing nb_conda within your environment. It would pull many dependencies, but that’s it. Now, you should see your in the menu. A related stack-overflow: https://stackoverflow.com/questions/39604271/conda-environments-not-showing-up-in-jupyter-notebook

source activate <new_env_name>
conda install nb_conda
source deactivate

To remove an environment.

conda remove --name <new_env_name> --all