How to Install Plotly on Ubuntu

Install Plotly on Ubuntu

Installing Plotly on Ubuntu doesn’t have to be complicated. Whether you’re a data scientist, developer, or analyst, this comprehensive guide will walk you through every method to get Plotly up and running on your Ubuntu system. We’ll cover multiple installation approaches, troubleshoot common issues, and ensure you’re ready to create stunning data visualizations.

Table of Contents

What is Plotly and Why Use It?

Understanding Plotly’s Capabilities

Plotly is a powerful, open-source graphing library that makes interactive, publication-quality graphs online. It’s become the go-to choice for data visualization professionals because it supports over 40 unique chart types, including scientific charts, statistical charts, maps, financial charts, and 3D graphs.

What sets Plotly apart is its interactive nature. Unlike static plotting libraries, Plotly creates visualizations that users can zoom, pan, hover over, and manipulate in real-time. This interactivity makes it perfect for creating dashboards, presentations, and web applications.

Benefits for Data Visualization

The library integrates seamlessly with popular data science tools and supports multiple programming languages including Python, R, and JavaScript. For Ubuntu users, Plotly offers exceptional cross-platform compatibility and performs excellently on Linux systems.

According to recent developer surveys, over 60% of data scientists prefer interactive visualization tools over static ones, making Plotly an essential skill in today’s data-driven world.

Prerequisites for Installing Plotly on Ubuntu

System Requirements

Before diving into the installation process, let’s ensure your Ubuntu system meets all requirements. Plotly works on all modern Ubuntu versions, including Ubuntu 18.04, 20.04, 22.04, and the latest 24.04 LTS.

Your system should have at least 2GB of RAM and sufficient storage space for Python packages. While Plotly itself is lightweight, some extensions and dependencies can require additional space.

Python Version Requirements

Plotly requires Python 3.6 or later. Most recent Ubuntu installations come with Python 3 pre-installed, but it’s important to verify your version. The latest Plotly releases work best with Python 3.8 or newer.

Essential Ubuntu Packages

You’ll need several essential packages that might not be installed by default:

  • python3-dev for development headers
  • python3-pip for package management
  • build-essential for compiling certain dependencies
  • curl or wget for downloading packages

Method 1: Installing Plotly Using Pip

Updating Your Ubuntu System

Start by updating your Ubuntu system to ensure you have the latest package information:

sudo apt update
sudo apt upgrade -y

This step is crucial because outdated package lists can lead to installation conflicts or missing dependencies.

Installing Python and Pip

Most Ubuntu systems come with Python 3 pre-installed, but you might need to install pip separately:

sudo apt install python3 python3-pip

Verify your installation:

python3 --version
pip3 --version

You should see version numbers for both commands. If Python shows version 3.6 or higher, you’re ready to proceed.

Basic Plotly Installation

Now for the main event – installing Plotly using pip:

pip3 install plotly

This command downloads and installs Plotly along with its essential dependencies. The process typically takes 1-3 minutes depending on your internet connection.

For system-wide installation (requires administrator privileges):

sudo pip3 install plotly

Pro tip: Avoid system-wide installations when possible. Virtual environments are safer and more manageable.

Verifying the Installation

Test your installation by running a simple Python script:

python3 -c "import plotly; print(plotly.__version__)"

If you see a version number (like 5.17.0), congratulations! Plotly is successfully installed.

Method 2: Installing Plotly Using Conda

Installing Miniconda on Ubuntu

Conda offers superior dependency management compared to pip, especially for data science workflows. First, download and install Miniconda:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

Follow the installation prompts and restart your terminal session.

Conda Installation Commands

Install Plotly using conda-forge channel:

conda install -c conda-forge plotly

Conda automatically resolves dependencies and often provides better performance than pip installations, especially for scientific computing packages.

Managing Conda Environments

Create a dedicated environment for your Plotly projects:

conda create -n plotly-env python=3.9 plotly
conda activate plotly-env

This approach isolates your Plotly installation from other projects, preventing version conflicts.

Setting Up Virtual Environments for Plotly

Why Use Virtual Environments?

Virtual environments are absolutely essential for Python development. They prevent package conflicts, allow multiple Python versions, and make project management much easier. Think of them as separate containers for different projects.

Creating a Virtual Environment

Using Python’s built-in venv module:

python3 -m venv plotly-venv

This creates a new directory called plotly-venv containing an isolated Python environment.

Activating and Managing Your Environment

Activate your virtual environment:

source plotly-venv/bin/activate

You’ll notice your terminal prompt changes, showing (plotly-venv) at the beginning. Now install Plotly:

pip install plotly

When you’re done working, deactivate the environment:

deactivate

This workflow ensures clean project separation and makes dependency management straightforward.

Installing Additional Plotly Extensions

Plotly Express Installation

Plotly Express provides a simplified interface for creating common visualizations. It’s now included with Plotly, but you can explicitly install it:

pip install plotly[express]

This ensures you have all optional dependencies for Plotly Express functionality.

Jupyter Widget Support

For interactive Plotly visualizations in Jupyter notebooks:

pip install jupyter anywidget

Installing Jupyter and AnyWidget

If you’re working in Jupyter environments, these packages enable seamless integration between Plotly and notebook cells. The anywidget package specifically handles the interactive components.

After installation, restart your Jupyter server to enable the widgets:

jupyter lab --generate-config

Static Image Export Setup

Installing Kaleido Package

For exporting Plotly graphs as static images (PNG, JPG, PDF, SVG), install Kaleido:

pip install kaleido

Kaleido is the recommended solution for static exports as of Plotly version 4.9. It has no external dependencies and works across all platforms.

Legacy Orca Setup (Optional)

While Kaleido is preferred, some users might need the legacy Orca tool. Installation is more complex and requires additional system dependencies, so stick with Kaleido unless you have specific requirements.

Extended Geographic Support

Installing Plotly-Geo Package

For advanced geographic visualizations, install the plotly-geo extension:

pip install plotly-geo==1.0.0

Working with Geographic Data

This package provides access to detailed geographic shape files needed for county-level choropleth maps and other specialized geographic visualizations. The package is relatively large (several hundred MB) due to the geographic data files.

Testing Your Plotly Installation

Running Your First Plot

Create a simple test script to verify everything works:

import plotly.graph_objects as go
import plotly.express as px

# Simple line plot
fig = go.Figure(data=go.Bar(x=['A', 'B', 'C'], y=[1, 3, 2]))
fig.show()

Common Test Scripts

Here’s a more comprehensive test that checks multiple Plotly features:

import plotly.express as px
import plotly.graph_objects as go
import pandas as pd

# Test data
df = px.data.iris()

# Create scatter plot
fig = px.scatter(df, x="sepal_width", y="sepal_length", 
                 color="species", title="Iris Dataset")

# Test if plot renders
if fig:
    print("✓ Plotly installation successful!")
    fig.show()
else:
    print("✗ Installation verification failed")

Troubleshooting Installation Issues

If you encounter import errors, check these common solutions:

  1. Module not found: Ensure you’re using the correct Python environment
  2. Permission errors: Use virtual environments instead of system-wide installation
  3. Version conflicts: Update pip and setuptools: pip install --upgrade pip setuptools

Best Practices for Plotly on Ubuntu

Performance Optimization Tips

To get the best performance from Plotly on Ubuntu:

  • Use virtual environments for project isolation
  • Keep your Plotly version updated: pip install --upgrade plotly
  • For large datasets, consider using Plotly’s WebGL-enabled scatter plots
  • Close unused browser tabs when working with interactive plots

Managing Dependencies

Create a requirements.txt file for your projects:

plotly>=5.0.0
pandas>=1.0.0
kaleido>=0.2.0

This makes it easy to reproduce your environment on different systems or share with team members.

Common Installation Problems and Solutions

Permission Issues

If you get permission denied errors:

  • Never use sudo with pip in virtual environments
  • Check directory ownership: ls -la ~/.local/
  • Use virtual environments to avoid system conflicts

Python Version Conflicts

Multiple Python versions can cause confusion:

  • Use python3 -m pip instead of just pip
  • Check which Python you’re using: which python3
  • Consider using pyenv for Python version management

Package Dependency Problems

Dependency conflicts are common in complex environments:

  • Start with a fresh virtual environment
  • Use pip check to identify conflicts
  • Consider using conda for better dependency resolution

Frequently Asked Questions (FAQs)

1. Do I need to install Python separately before installing Plotly on Ubuntu?

Most Ubuntu systems come with Python 3 pre-installed. You can check by running python3 --version. If it shows version 3.6 or later, you’re ready to install Plotly. If not, install it using sudo apt install python3 python3-pip.

2. What’s the difference between installing Plotly with pip vs conda?

Pip is simpler and faster for basic installations, while conda provides better dependency management and is preferred for data science workflows. Conda automatically resolves conflicts and often includes optimized versions of scientific libraries.

3. Can I install Plotly system-wide or should I use virtual environments?

While you can install Plotly system-wide using sudo pip3 install plotly, virtual environments are strongly recommended. They prevent conflicts between projects and make it easier to manage different versions of packages.

4. Why am I getting “Module not found” errors after installing Plotly?

This usually happens when you install Plotly in one Python environment but try to import it from another. Ensure you’re using the same Python interpreter and environment where you installed Plotly. Check with which python3 and pip3 list.

5. Do I need additional packages for creating interactive plots in Jupyter notebooks?

Yes, for full Jupyter support, install the additional packages: pip install jupyter anywidget. These enable interactive widgets and proper rendering of Plotly graphs within notebook cells. Restart your Jupyter server after installation.

Marshall Anthony is a professional Linux DevOps writer with a passion for technology and innovation. With over 8 years of experience in the industry, he has become a go-to expert for anyone looking to learn more about Linux.

Related Posts