Tutorial for managing conda environments
https://conda.io/docs/user-guide/tasks/manage-environments.html
- Make sure Anaconda is installed: https://www.anaconda.com/download/
-
Create new environment, called "env1" with python 2.7 the package, ipython:
conda create --name env1 python=2.7 ipython
-
Activate your new environment
source activate env1 # remove source for windows
-
Use ipython to see if it worked
ipython import sys sys.executable sys.version quit
You should see something similar to this:
(env1) D-10-19-251-209:~ cswitzer$ ipython Python 2.7.15 |Anaconda, Inc.| (default, May 1 2018, 18:37:05) Type "copyright", "credits" or "license" for more information. . . . In [1]: import sys In [2]: sys.executable Out[2]: '/Users/cswitzer/anaconda/envs/env1/bin/python' In [3]: sys.version Out[3]: '2.7.15 |Anaconda, Inc.| (default, May 1 2018, 18:37:05) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]'
-
Deactivate the environment
source deactivate
- Create new environment, called "env2" with python 3.7 and the package ipython
- Activate that environment.
- Run ipython, and check to see if you're using the python version from your new environment
-
Install
ipykernel
in your new environmentsource activate env1 conda install ipykernel
-
Use the package
ipykernel
to install kernel, so you can use that environment in jupyter notebook-
install kernelspec for this user
python -m ipykernel install --user --name env1
-
check to see if the kernel has been installed
jupyter kernelspec list
-
deactivate environment
source deactivate #remove "source" for windows
-
run jupyter lab
jupyter lab
-
Start a new jupyter noetbook
-
check to see if you can select your new environment (Kernel -> change kernel -> env1)
-
use
sys
to check the environment and python version
-
- install a kernel for your new environment
env2
- Run
jupyter lab
, and check to see if the new environment is available
- Download the file
environment.yml
https://github.com/callinSwitzer/conda_env_tutorial/blob/master/environment.yml - In terminal (or anaconda prompt), navigate to the folder where you saved this file.
- Create a new environment, using this file (may take ~2 min to finish)
conda env create -f environment.yml
- List environments
conda env list
- Install kernel
source activate machLearn_env python -m ipykernel install --user --name machLearn_env
- Check to see if this kernel is available in Jupyter lab
- Create an exact environment.yml file (note that this will overwrite any environment.yml file in your current directory)
source activate env1
conda env export > environment2.yml
- Edit this exported file (by hand) to make it simpler
- List all conda environments
conda env list
-
To remove an environment, delete it's folder
-
List kernels
jupyter kernelspec list
- To remove a kernel, delete it's folder
*** OPTIONAL: Remove unused packages and caches
conda clean --all --dry-run # do a dry run first, without deleting anything
conda clean --all # actuall delete the things