Installing Jupyter Notebook for Different Environments in Windows 10 | by Bipin P. | Towards Data Science

To install Jupyter Notebook in various virtual environments and how to deal with the pywin32 error that may encounter in Windows 10.
A virtual environment is an isolated region where a particular version of Python and its packages are installed enabling the installation of different versions of Python. Each environment has its own files, directories, and paths. Thus a single system can cater to different projects that demand different Python versions.
For Python installation and its basics, refer to my blog here:
towardsdatascience.com
Assuming that Python is already installed in your system(using Anaconda Individual Edition), open the Anaconda prompt and type the command ‘conda info — envs’. It will list the number of environments in your system. The current virtual environment will be indicated by an asterisk. In the image shown below, there are two environments viz. base and Python 3_8. The current environment is base.
Before installing Jupyter Notebook, pip(Python Package Installer) should be installed by the following command:
conda install pip
Jupyter Notebook should now be installed:
pip3 install jupyter
So Jupyter Notebook will now be installed for the base environment. To switch to a different environment, type conda activate environment_name:
conda activate Python3_8
Suppose we want to upgrade Python to version 3.9. It is recommended to do the up-gradation in a new virtual environment as the new stable version often has conflicts with Python packages initially. Hence it is advisable to keep the older version. The command conda create -c conda-forge python=3.9 -n Python3_9 installs Python version 3.9 in a new virtual environment Python3_9.
Verify the presence of the new environment:
Let’s activate Python3_9 environment by ‘conda activate Python3_9’ command.
Type ‘Jupyter Notebook’ to start the notebook. However, an error occurred -’Jupyter’ is not recognized as an internal or external command, operable program or batch file. Now it's obvious that Jupyter Notebook is not installed in the current environment.
Let’s install it.
Now try running the notebook:
The Jupyter Notebook successfully opened in the browser.
However, we have encountered an error that is represented by the red button with the ‘Kernel error’ text. Clicking on that red button gives more details about the error-ImportError: DLL load failed while importing win32api: The specified module could not be found.
The win32 error can be amended by installing pywin using pip3:
Requirement already satisfied. Then what could be triggering the error? The error can be rectified by the command:
python [environment path]\Scripts\pywin32_postinstall.py -install
Here the environment path is \users\bipin\anaconda3\envs\python3_9. If installed correctly, you will receive the message ‘The pywin32 extensions were successfully installed.’
Now let’s try running Jupyter Notebook. The conda active environment and other details can be had by running the command ‘!conda info’:
To run Jupyter Notebook from any desired location, please visit my blog here:
iambipin.medium.com
You may also know the path of the current environment by ‘print(sys.executable)’. The sys.executable command provides the absolute path of the executable binary for the Python interpreter.
I am pretty sure most of you might have encountered this error while installing Jupyter Notebook. Hope you learned something new. Happy Coding!!!