Jupyter Notebook wrong directory. Unable to import seaborn


I’m working in Win10. I’m very new to Python and JupyterNotebook so any help is appreciated but I might need more elaborate help in terms of steps.

Anyways, it started when I first installed Anaconda and was importing seaborn in Jupyter notebook but it gave me the error “ModuleNotFoundError: No module named ‘seaborn’”
I realized that it’s pointing at the wrong directory - from ArcGIS Pro…

And upon opening Jupyter Notebook, it shows “JupyterLab application directory is C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\share\jupyter\lab”

When I checked the kernel, there’s only one and it’s at the correct location:
Available kernels:
python3 C:\Users\sherl\anaconda3\share\jupyter\kernels\python3

Now, how exactly do I change the directory to the right location in “C:\Users\sherl\anaconda3”? I’ve looked on stack overflow but I just cannot figure it out.

Thank you!

I could temporarily fix the issue and change the directory using [this] (Change IPython/Jupyter notebook working directory - Stack Overflow):

jupyter notebook --notebook-dir=/Users/yourname/folder1/folder2/

But once close anaconda and restart notebook it’s gone.

In your notebook at the top add the following in a cell:

%pip install seaborn

For what is behind the %pip magic, see bottom couple of paragraphs here where it begins ‘Alternatively, you can put the following lines …’.

Hello! Thank you for the reply. I got the following error when I do that:

Ah. Windows. I don’t think it will help since something about your Windows situation is an issue but you can try %conda install seaborn.
I assume you also tried restarting the kernel after %pip install?

Yup. I’ve tried pip install, conda uninstall, conda install. and also restarting kernel. none of it works because I think it’s at the wrong path → linking to the python in ArcGIS folder :frowning:

This post is using linux in Windows; however, it looks similar to your issue. Especially the tip; " This usually happens when Jupyter Notebook gets opened from another python environment ." Or this thread/solution? However, I’d be cautious. At this point you don’t want to make the situation worse. I’d suggest working with Virtual Environments if you insist on using local installs where you have to play nice alongside with other things you’ve installed locally. In your case it looks like an ArcGisPro set up? Have you looked into Python Virtual Environments when you were seeking how to add Jupyter notebooks? See Why Can't Python Find My Modules? – Real Python , which leads to Working With Python Virtual Environments.
Even if some Anaconda/Windows guru comes along now and sees the solution to your present issue, it is a nice tool to be familiar with as you go forward more with Python/Jupyter. In the past I used it for testing new Python versions when I didn’t want to impact other situations on my local drive. However, I try to avoid working truly local anymore and either work in remote sessions of one type or another or in Docker containers. These types of solutions help keep things more reproducible in the long run

1 Like

I had the same problem. To solve this, it was necessary to type: pip install seaborn or pip3 install seaborn in GitBash or in the terminal you use to open Jupyter.
When the installation is finished, just click on Restart Kernel.

See you later! :brazil: @danieledamaris

1 Like

In case you didn’t catch it, above @DanieleDamaris I suggested running %pip install seaborn in the notebook. This has the advantage that it should install the package to the same environment backing the notebook without the user needing to sort out which version is backing the environment being used by the notebook. It’s a useful practice for Jupyter work, and also works for conda installs, see here for more information.
But you are right, since that didn’t seem to fix the situation, it wouldn’t hurt in this case to try installing the way you suggest.
The magic route should work most times on up to date systems and installs, and since it makes things so much easier for new learners I wanted to highlight it further in this thread.

Thanks for answering this question. It’s very helpful :slight_smile:

Have you been opening Jupyter from the Anaconda Navigator home page?