drawsvg is a Python 3 library designed for programmatically generating SVG (Scalable Vector Graphics) images and animations. It supports rendering drawings to various formats including PNG and MP4, and allows for interactive display within Jupyter Notebook and Jupyter Lab environments. The library maintains an active development status with regular updates, with version 2.4.1 being the latest stable release.
pip install "drawsvg~=2.0"Verified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a simple SVG drawing with a circle, rectangle, and text. It then saves the output to an SVG file. Instructions for displaying in Jupyter Notebook and saving to PNG are also included, highlighting the optional dependencies for the latter.
Update all method/argument calls and import statements to use `snake_case` and the lowercase package name `drawsvg`. Adjust Y-coordinate logic where necessary.
Install Cairo on your operating system (e.g., `sudo apt-get install libcairo2` on Ubuntu, `brew install cairo` on macOS) and ensure `drawsvg` is installed with the `[all]` extra.
If interactive widget functionality is crucial, use Jupyter Notebook instead of Jupyter Lab.
For raster output, ensure you are using system-installed fonts or fallback fonts that are universally available and don't rely on embedded custom fonts.
Change your import statement from `import drawSvg` to `import drawsvg`.
Update the method call to `snake_case`, e.g., change `d.saveSvg('file.svg')` to `d.save_svg('file.svg')`.Install the Cairo library at the system level (e.g., `sudo apt-get install libcairo2` on Ubuntu or `brew install cairo` on macOS).