Lib importation in python

I’m trying to import matplotlib in my project, but have ModuleNotFoundError.

Try the following in order until your import works. If it doesn’t work but something changes, let us know what changes relative what you show above.

In a Jupyter cell run the following:

%pip install matplotlib

Restart the kernel for the notebook using the menu above the notebook Kernel > Restart. And then try import matplotlib.pyplot as plt as a cell in the notebook.

If that fails…
In a Jupyter cell run the following:

%pip install --upgrade --force-reinstall matplotlib

Restart the kernel for the notebook using the menu above the notebook Kernel > Restart. And then try import matplotlib.pyplot as plt as a cell in the notebook.

If that fails…
I’m guessing based on your initial post that you aren’t using anaconda/conda yet? In other words, you haven’t been using conda install anywhere? (However, if you are using conda immediately repeat the first suggestion above, replacing pip with conda. Then try the second suggest but replace the upgrade command with %conda update matplotlib).

Try installing Anaconda/conda (see here) and using an environment in which to run Jupyter, see here and here about using an environment to run your Jupyter, separate & isolated from the default Python and Jupyter on your system. After you are in the environment and running a notebook start over with the suggestions in order above. Hopefully the first one will work now.

2 Likes