Jupyter Notebook errors

Hi Yin,
Are you running Jupyter Notebooks on a Mac or PC?

Also, are you using Anaconda on a Mac? I know from experience there are issues w/Mac’s Catalina and Anaconda (which I still have and haven’t quite figured out yet myself).

Did you try re-running the kernels in the notebook?

Also, I wonder if it’s an issue in how you installed Matplotlib…? Did you use Conda or pip install?
https://stackoverflow.com/questions/36343430/jupyter-gets-import-error-when-importing-matplotlib

Hello Lisa, thanks for your reply.

I use Jupyter Notebook on a Mac.

To answer your follow-up question… I’m going to be completely honest with you. I kind of know the difference between Anaconda and Miniconda but that’s it regarding my knowledge of the two. A tutorial to install Jupyter Notebook (I believe, I’m not sure. Could’ve been something else as well) advised me to install Miniconda, because it’s smaller in size. So I’m not sure whether I installed Anaconda or not.

I also do not know what you mean with ‘re-running the kernels’. I’ve read something about that before I posted here and I clicked some buttons but nothing seemed to be working.

And I also don’t know how I installed Matplotlib. Or if it’s installed in the first place. I guess I should try and install it first and see if it works.

I’m a complete beginner at this so even though your answer is probably very thorough, it’s gonna take a bit more to fix it. Sorry :slight_smile:

No apologies necessary. I’m a beginner too! :slight_smile: We are always learning.

I updated to Catalina and then couldn’t access Anaconda Navigator (it’s a known issue that hasn’t been fixed by Anaconda. There are work arounds but the one I tried didn’t work). I searched online and thought I’d fixed it but it didn’t. doh!

I think the default python used on Macs is 2.7 and you have to make sure you’re using the most current version of python which is 3.8(?) type python --version in your terminal window.

Anyway, this isn’t a fix, but a temporary one: can you switch to using Google’s Colab rather than Jupyter? There’s lots of pre-installed modules there but some you have to install.

Maybe someone else can chime in here if they have any ideas… :slight_smile:

did you try (in your terminal window)?
pip3 install jupyter

pip3 install matplotlib

I also just did a pip3 install pandas and a pip3 install seaborn
then re-ran the cells in my notebook. I think it worked… b/c I didn’t get any errors when running the cells, ie: the modules were imported.

https://stackoverflow.com/questions/43437884/jupyter-notebook-import-error-no-module-named-matplotlib

Also, I found this article. It might be helpful(?). I followed the steps and did those pip3 installs.
https://medium.com/towards-artificial-intelligence/how-to-run-jupyter-notebook-on-macos-catalina-in-four-steps-f7cc4e2cc270

1 Like

I have literally no idea what I downloaded or how it connects to Python (version 3.7.7, I checked it). Probably because it’s not exactly ‘visible’.

But it worked… thank you so much!

1 Like

the pip3 install worked?

Also, do you initialize Jupyter in your terminal window? (b/c the Anaconda Navigator app doesn’t work after Catalina b/c the folders were moved to a “Relocated Items” folder. I think you have to change the directory for Anaconda for Navigator to work [but I’m not 100%]

Yes the pip3 install method worked for me.

And yes, I initialise (I assume you mean start the Jupyter application) Jupyter using the Terminal.

1 Like

Oh, and the reason why pip3 install works is b/c it installs packages for python 3 and higher (rather than just using pip install.)
:slight_smile:

1 Like

Well, isn’t that awkward. One day later and a new error arises. It’s a similar error like last time. And this time, I know what to do. However, typing pip3 install pandas and pip3 install seaborn didn’t work because apparently, it’s already on my Mac.

Based on your feedback from the last time, it could be that it’s in a different folder. But then, where should I put it? The photo shows where it is located right now.

Thanks :sweat_smile: :sweat_smile: :sweat_smile:

d’oh!
I had that issue yesterday w/pandas and seaborn not being recognized so I imported them and they live in my local directory.

Did you re-start the kernals in that notebook and then rerun that cell where you import the modules?

I clicked ‘Restart’, ‘Restart & Clear Output’ and ‘Restart & Run All’ but nothing happened unfortunately. Not sure how I can make my Pandas and Seaborn libraries live locally though.

Update: I did some Googling and even though I still had no idea what I was doing / downloading, I managed to find a solution that works.

This thread on Stack Overflow (https://stackoverflow.com/questions/33481974/importerror-no-module-named-pandas) provides the answer, see photo attached.

I may come back to this thread if I run into other problems :sweat_smile:

From your screenshot, they are in your local library.

I’m not sure if “Run All” runs the cells in order. ? Did you run the cells in order (again)?

I’m kind of at a loss. I will also research the issue and report back if I find anything.

If you get the chance try having a look into working with virtual environments as Python’s package management can be a nightmare at times (especially when you have to avoid affecting your system python install). I’d say it’s well worth investing a little time into getting to know your way around virtual environments now rather than constantly worrying about what’s installed where.

I’d suggest having a look at python’s own venv and perhaps pipenv (PyPI) to try and keep things in order-

https://docs.python.org/3.8/library/venv.html

Anconda also has it’s own system of environments that you could also try to work with if that’s your preference.
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

1 Like

Cool, thank you.

I primarily use Colab, but, if I go back to Jupyter, I will give this a shot.

1 Like

I’ve not tried Colab before but when it comes to some of the projects I’ve been working on the whole version management thing became essential since things start breaking left, right and centre otherwise. Don’t get me wrong it’s still a bit of a mess but it’s nice having that safety net of just being able to make/remake an environment with all the packages (and their specific versions) you require with just a couple of quick shell prompts. It took a while to get used to it but it was definitely well worth it.

What’s Colab and how does it differ from Jupyter Notebook and, let’s say, PyCharm?

Also, could you please explain to me what you mean with working in a virtual environment rather than Jupyter? And how does it work? Thanks :slight_smile:

It’s a cloud platform based off of jupyter notebook. Use it to write python commands in your browser, machine learning, data analysis, etc. You can also connect to a SQL server using sqlalchemy from sqlalchemy import create_engine

You can mount your Google Drive to it and upload csv files or upload files locally.
https://colab.research.google.com/notebooks/intro.ipynb

Jupyer itself isn’t really related to virtual environments, it’s just a well known interactive interpreter for Python (and others). Virtual environments are a way of controlling versions and package dependency for your Projects. Each one is like it’s own little bubble that is, ideally, not affected by any system changes and can run a different version of Python and perhaps more importantly the same for any site-packages a.k.a. all the useful third-party packages (numpy/pandas/matplotlib etc. etc.) you end up using daily.

Practically you’d be creating a virtual envionment and then installing the Jupyter packages (and any others e.g. matplotlib) within this environment. By isolating it you can manage your project dependencies in a much easier manner and have confidence that it won’t suddenly break because that new package you installed to deal with database requests on a different project hasn’t suddenly overwritten some of the packages Jupyter needs to run.

Apologies for replying with a link but I think it’ll be more helpful than what I can manage in a single reply-