Python No module named 'seaborn'

I’m working on Python 1 for Power BI users. Working through the module Python visuals and Spyder IDE.

The module calls for the library Seaborn to be imported using import seaborn as sns. I get an error that says
File “C:\Users\tyebr.spyder-py3\temp.py”, line 9, in
import seaborn as sns

ModuleNotFoundError: No module named ‘seaborn’

I’ve gone into the command prompt and installed seaborn. Then closed and re-opened sypder and tried again with the same results. What’s the next troubleshooting steps to pursue?

Image of Seaborn installation

Image of Spyder after installation and second attempt

I don’t use Spyder but that shouldn’t matter if you’re running python from a .pbix file. Is this what you’re doing?

PowerBI runs python by default from your local python install. If you’re running a virtual environment - make sure you reconfigure by going to options and settings

No, this error is before we put the code into Power BI. At the point where I’m stuck in the instructions the only thing that has been done is to open spyder and import the libraries. So

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

When I remove import seaboarn as sns the program runs fine importing the other libraries. Is there something that would work within an IDE?

Oh I see. I don’t think this is the correct forum but happy to help if I can.

This problem looks similar to yours. Make sure you have added Python to your Path

From Spyder, you need to understand which python version you’re running and where the python.exe file is saved. You might have multiple different versions on your machine eg:

  • C:\Users\Pattis\AppData\Local\Programs\Python\Python39

  • C:\Users\Pattis\AppData\Local\Programs\Python\Python36

  • C:\Users\Pattis\Documents\Python\Python36

Once you know which python version you’re using in Spider, you need to install seaborn for that particular environment (each environment has one python.exe file).

Check if seaborn is installed for Spyders selected python version using Command Prompt CMD. The below command -m pip list will list all packages you have installed. (Replace the path below with the one you’ve confirmed Spyder is using):

C:\Users\Pattis\AppData\Local\Programs\Python\Python39 -m pip list

if seaborn isn’t there you need to install it using pip module:
C:\Users\Pattis\AppData\Local\Programs\Python\Python39 -m pip install seaborn

Goodluck and don’t give up. Setting up python environments is hard especially in Windows.

2 Likes

Thank you so much for that detailed answer @izzleee

We hope this helped you @Tye:slight_smile:

If not, how far did you get and what kind of help you need further?

If yes, kindly mark as solution the answer that solved your query.

The instructions called for a new path to be created. I’m supposed to add the Python application and Python script to an path. I was able to find the Python application. However there isn’t a script listed in the folder. Here’s what the folder shows. What should I do if the Python script isn’t listed?

Thanks

Hi Tye,

Now that you know where your python.exe file is running from spyder, install seaborn. Something like:

C:\Program Files\Spyder\Python -m pip install seaborn

This file path points to the exe file and explains to your machine which tool to use, then how to use the tool i.e which module (pip in this case) and the option (install).

Now try running your script from within Spyder.

It’s fixed!! I should have mentioned that the spyder I was using was under the anaconda suite. When I opened anaconda there was a notice of a new version. I got an error when I attempted to update so I deleted everything that had to do with anaconda. Installed the updated version and its working fine.

Thanks for your help. Appreciate you working with me

1 Like