Skip to content

How to Install Seaborn in Python (Fix: no module named seaborn)

How to Install Seaborn in Python Fix no module named seaborn Cover Image.png

In this tutorial, you’ll learn how to install the Seaborn library using Python. You’ll also learn how to fix the no module named seaborn error. The Seaborn library builds on top of Matplotlib to make statistical visualization simple and intuitive to create.

By the end of this tutorial, you’ll have learned the following:

  • How to install Seaborn with Python, using pip
  • How to fix the no module named seaborn error

Want to learn more about installing packages in general? Check out this guide on installing external libraries in Python.

Prerequisites for Installing Seaborn

In order to install Seaborn, there are two main dependencies:

  1. Python 3.7 or later. Seaborn no longer supports Python version 2.
  2. Either pip or conda

In addition to these requirements, Seaborn actually requires NumPy, Pandas, and Matplotlib. Because it builds statistically complex visualizations, it also requires either scipy or statsmodel.

How to Install Seaborn on Windows Using pip

The simplest way to install the Seaborn library on Windows is to use the Python pip package manager. In order to install the latest version of the library, you can simply call the following command in the command prompt:

python -m pip install seaborn

To install a specific version of the library, such as version 0.12.1, you can write the following command:

python -m pip install seaborn==0.12.1

It’s as easy as that! In the following section, you’ll learn how to install the requests library on macOS using the pip package manager.

How to Install Seaborn on macOS Using pip

Similar to the Windows method, the simplest way to install the Seaborn library on macOS is by using the pip package manager. On macOS, this is done by using the Terminal application. When in the Terminal application, simply run the following command:

pip install seaborn

Similar to installing a specific version on Windows, to install a specific version of the library, such as version 0.12.1, you can write the following command:

pip install seaborn==0.12.1

In the following section, you’ll learn how to install the Seaborn library on Linux.

How to Install Seaborn on Linux Using pip

To install the seaborn library using the pip package manager on Linux, you can use the terminal application. When the application is open, you can run the following command:

pip install seaborn

Similar to the above example, to install a specific version of the library, such as version 0.12.1, you can write the following command:

pip install seaborn==0.12.1

In the following section, you’ll learn how to install the requests library in a virtual environment.

How to Install Seaborn in a Virtual Environment

Using a virtual environment is a good idea for many reasons. For one, it allows you to better understand what versions of libraries you’re using. Additionally, it allows you to keep a cleaner development environment.

Installing the seaborn library in a virtual environment works the same as the methods above, though we first have to create and activate the virtual environment. You can create and activate the environment on Windows using the method below:

python -m venv venv
.\venv\Scripts\activate

On macOS, you can write the following:

virtualenv venv
source venv/bin/activate

Once the environment has been created, you can use any of the pip methods shown above to install the requests library. This is summarized in the code block below:

# On Windows:
python -m pip install seaborn

# On macOS or Linux
pip install seaborn

In the following section, you’ll learn how to install the library using a requirements.txt file.

How to Install requests With requirements.txt

Using a requirements.txt file is particularly helpful when sharing your code with others via source code management tools, such as Github. The file provides the ability to easily track and identify the packages that you use in a project.

In order to use the requirements.txt file to install the seaborn library, you can insert a file name requirements.txt to the root folder of your project. In the file, include a line containing requests.

From there, you can use the pip package manager to install all libraries listed in the file. This can be done using the following command:

pip install -r requirements.txt

In the final section below, you’ll learn how to install the requests library directly from Github source code.

How to Install requests from Github

If you have Git installed, you can install the requests library directly from the source code. This allows you to install the library from its code directly.

In order to do that, you can use the pip package manager, though you pass in the URL to the source code directly.

pip install git+https://github.com/mwaskom/seaborn.git

Doing this can help you feel confident that the code you’re installing is the code you want to use.

How to Fix the No Module Named Seaborn Error

When you try to run a program that imports Seaborn, you may encounter the following error:

ModuleNotFoundError: No module named seaborn

In general, this means that Seaborn has not been installed (or installed correctly). In order to resolve the issue, you can simply install Seaborn using any of the methods described above.

For example, you can simply write the following command into your terminal:

pip install seaborn

Another common issue that you might encounter is using an incompatible version of Python. Because Seaborn has very strict requirements around recent versions, this is an important thing to check.

Seaborn requires at least Python 3.7 and is not compatible with Python version 2. In order to check the version of Python, you can run the following command:

python --version

If you’re not running Python 3.7 or later, you can install a later version of Python.

Frequently Asked Questions

How can you install Seaborn in Python?

In order to install the Seaborn library in Python, you can use either “pip install seaborn” or “conda install seaborn”, depending on which package manager you use.

How you fix the ModuleNotFoundError: No module named seaborn error in Python?

The ModuleNotFoundError indicates the the module has not been installed correctly. In order to resolve this, you can install the library using “pip install seaborn”.

Conclusion

In this tutorial, you learned how to install Seaborn in Python. You learned how to install the Seaborn library using the pip package manager in Windows, macOS, and Linux. You also learned how to install the library in virtual environments and directly from Github. From there, you learned how resolve the ModuleNotFoundError: No module named seaborn error. The error occurs when the Seaborn library has not been installed or not installed correctly.

Additional Resources

To learn more about related topics, check out the resources below:

Nik Piepenbreier

Nik is the author of datagy.io and has over a decade of experience working with data analytics, data science, and Python. He specializes in teaching developers how to use Python for data science using hands-on tutorials.View Author posts

Leave a Reply

Your email address will not be published. Required fields are marked *