On Windows, choose Anaconda Prompt or Command Prompt from the start menu. On Mac select Terminal. You can also call up a terminal in Jupyter Notebooks by choosing 'New' and 'Terminal'.
In the terminal, enter the command below to create a new virtual environment. In this example, MyEnv is the name used for the environment, replace this with your chosen name.
conda create -n MyEnv python=3.7
Press 'y' and return when asked to proceed. All packages will be downloaded and installed.
Run source active MyEnv
to activate your virtual environment. Again, substitute your environment name for MyEnv. You should now see a prompt with the name of your environment in parentheses. On some computers, use conda activate MyEnv
instead of source activate MyEnv
.
Now that you're in your virtual environment, install packages using conda install
or pip install
. For example, to install Seaborn, type:
conda install seaborn
Hint 1: we recommend using conda install
first, as it automatically installs other low-level libraries that your new library requires. Use pip install
as an alternative option. Some libraries use custom conda channels (eg. conda-forge) in which case their documentation will indicate a slightly different installation command (eg. conda install -c conda-forge osmnx
).
Hint 2: you can append -y to your statement to automatically proceed without being prompted for confirmation. Consult this Conda Cheat-Sheet for more commands and short-cuts.
For your environment to work on Jupyter notebooks, you need to install ipykernel as follows:
conda install ipykernel
Now create the kernel for your environment by running:
python -m ipykernel install --user --name MyEnv --display-name MyEnv
Navigate back to the Home tab on Jupyter Notebooks in your browser. Make sure to refresh the page. Now click the New button and select the name of your kernel, which is MyEnv in this example.
You can now import and use the packages from your kernel. Notice the Seaborn package imports successfully:
import seaborn as sns