Sometimes we would like to write code with a specific Python version and/or library because, for example, some libraries work only on Python 3.5, not 3.6. Then we need to create a virtual environment for the project.
The following lines are supposed to be run in Anaconda prompt on Windows or a shell on Mac.
conda create -n NAME_OF_ENVIRONMENT python=3.5 anaconda
We can choose the name of environment arbitrary. Then, on Windows, a corresponding Anaconda prompt like "Anaconda prompt (***)" would be created. The environment can be used easily on Jupyter Notebook and PyCharm.
conda remove -n NAME_OF_ENVIRONMENT --all
conda info -e
activate NAME_OF_ENVIRONMENT
We are supposed to use "source activate ***" on Mac OS, but this line produces an error like "pyenv: -bash: command not found" possibly due to some conflict between pyenv and conda (2017.04.11). Then we need to specify the full path as
source ~/.pyenv/versions/anaconda3-2.5.0/bin/activate ***
Note that we should modify the line according to the position of pyenv root folder and the version of Anaconda.
deactivate NAME_OF_ENVIRONMENT
We should use "source deactivate ***" on Mac OS.
conda create -n *** --clone root
By doing this, we can make a backup (***) before updating the current environment (root).
(2017.7.7) I found that, when using jupyter notebook in multiple virtual environments, the kernel specification would be broken. Although I am not sure how this happens, the following procedure fixed this problem.