iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐍

How to Fix subprocess-exited-with-error When Installing svglib on Ubuntu

に公開

svglib is a Python library used for reading SVG files and converting them into other formats.
https://pypi.org/project/svglib/

Normally, you should be able to install it using pip install svglib. However, I ran into a subprocess-exited-with-error issue when installing it on Ubuntu within WSL2, so I have summarized the workaround here.


Environment

  • Windows 11 Pro 25H2
    • WSL2
      • Ubuntu 24.04 LTS
  • Python 3.10.16

The Issue

When running:

pip install svglib

I get the following error:

error: subprocess-exited-with-error

× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [20 lines of output]
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> pycairo

As the error suggests, this appears to be a problem related to Pycairo.

Looking at the svglib Dependencies, it states that it primarily depends on the reportlab package.

https://docs.reportlab.com/install/ReportLab_Plus_version_installation/
Furthermore, reading the ReportLab documentation confirms that it does indeed depend on Pycairo.

Installing Pycairo

The following is the documentation for Pycairo, which includes information regarding its dependent libraries.
https://pycairo.readthedocs.io/en/latest/getting_started.html

On Ubuntu/Debian, execute the following command to install the dependent libraries:

sudo apt install libcairo2-dev pkg-config python3-dev

In addition to the above, since the libraries required for the build process are not installed on Ubuntu in WSL2 by default, I also execute the following command:

sudo apt install build-essential

Once the dependency environment is set up, run:

pip install pycairo

to install Pycairo.


That is all.
With this, you can now successfully install svglib using pip install svglib.

Other articles on the web did not have the dependencies organized and recommended installing unnecessary packages, but considering the dependency relationships of each library as of January 2026, I believe this content represents the minimal configuration.

I hope this proves helpful for those facing similar issues.

Discussion