Search code examples
cmdanacondaenvironment-variablessetx

I have added conda and python path to the environment variable, but jupyter notebook is still not getting opened from cmd


I was trying to add conda and python to the environment variable using SETX Command from CMD but it was failing. I tried setting it using PowerShell and it worked. The path was added successfully but I still can't open Jupyter Notebook from my cmd.


Solution

  • Adding Python to the environment path is bad practice, see Anaconda FAQ. If you haven't installed Anaconda with it's default settings, you first need to:

    Initialize your shells

    conda init --all
    

    After this you should have ../Anaconda3/condabin only in your path (more information via conda init --help).

    But before you can run Jupyter, you also need to activate Anaconda:

    C:\> conda activate
    (base) C:\> jupyter notebook
    

    The activation will add the following folders of the conda base environment to your PATH:

    \Anaconda3;
    \Anaconda3\Library\mingw-w64\bin;
    \Anaconda3\Library\usr\bin;
    \Anaconda3\Library\bin;
    \Anaconda3\Scripts;
    \Anaconda3\bin;
    

    The python.exe resides in Anaconda3, jupyter.exe in Anaconda3\Scripts, so it's not enough to just add the first folder to your Path. And it's especially important to have the libraries on your Path when you want to run C-based packages like numpy.

    But the very point behind the conda activate mechanism is that it allows you to configure and run different environments with different versions of python and 3rd party packages that would otherwise conflict, see Managing environmnts.

    On top of that you can even install Python from python.org next to your Anaconda distribution, since conda will make sure that they won't interfere.