Tip: Using Conda Environments with Jupyter on Windows
Configuring data science workspaces via PowerShell
Introduction
Conda environments don’t work well by default in PowerShell, and the environments don’t show up by default as kernels in Jupyter.
Using Conda Environments in PowerShell
Update 1/29/2019: Conda now officially supports PowerShell. Read more on the blog post.
The ease with which Conda environments can be used in PowerShell varies based on the
version of Conda installed. Check your version by running conda --version.
Version 4.6 and Later
With the version 4.6 update, Conda supports PowerShell natively. To configure for PowerShell, run the following:
PS> conda init powershell
The conda init command will modify the activate/deactivate scripts and make changes to your
PowerShell profile.
Prior to Version 4.6
You’ll need to install some additional software in order to use the activate/deactivate
commands in PowerShell. Specifically, install the helpful tool from Pavel Koneski
called PSCondaEnvs.
Note that if your PowerShell execution policy is Restricted (run Get-ExecutionPolicy to
check), you’ll need to set it to RemoteSigned by running the following:
PS> Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Now, install pscondaenvs with Conda:
PS> conda install -n root -c pscondaenvs pscondaenvs
Enter y when prompted to proceed.
Once pscondaenvs is installed, you’ll have new activate and deactivate
commands available that work in PowerShell.
Making Conda Environments Available in Jupyter
First, activate the desired environment by running conda activate myenv (or activate myenv
if using pscondaenvs).
Ensure dependencies are available by running the following:
(myenv) PS> conda install pip
(myenv) PS> conda install ipykernel
Type y to proceed as needed. After the installation completes,
run the following command to create a new ipykernel for this environment:
(myenv) PS> python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
You’ll see the “Python (myenv)” kernel available when you next launch JupyterLab.
Further Reading
Browse the conda documentation and the JupyterLab documentation for details on how these powerful tools can improve your data science workflow.
Update 2/4/2019: Added notes on new Conda 4.6 init and activation commands for PowerShell.