Why does lottie throw ImportError: cannot import name 'PngRenderer' from 'lottie.exporters.cairo'?
Question:
Why does lottie give the error ImportError: cannot import name ‘PngRenderer’ from ‘lottie.exporters.cairo’?
import lottie
from lottie.exporters.gif import export_gif
from lottie.parsers.tgs import parse_tgs
def convert_tgs_to_gif(tgs_file, gif_file):
try:
animation = parse_tgs(tgs_file)
export_gif(animation, gif_file, skip_frames=5, dpi=48)
return True
except Exception:
logging.exception("Error occurred while converting TGS to GIF.")
return False
Traceback errors:
Traceback (most recent call last):
File "C:UsersBubunducPycharmProjectstgmain.py", line 11, in <module>
from lottie.exporters.gif import export_gif
File "C:UsersBubunducPycharmProjectstgvenvlibsite-packageslottieexportersgif.py", line 5, in <module>
from .cairo import PngRenderer
ImportError: cannot import name 'PngRenderer' from 'lottie.exporters.cairo' (C:UsersBubunducPycharmProjectstgvenvlibsite-packageslottieexporterscairo.py)
I tried to import this library in different ways, tried to understand the source code
Answers:
Here the problem is in a completely different library. PngRenderer
requires the cairosvg
library. On windows, it requires libcairo-2.dll. Therefore, the solution to this problem is the correct installation of cairosvg
.
Answer about installing cairosvg
on windows.
Why does lottie give the error ImportError: cannot import name ‘PngRenderer’ from ‘lottie.exporters.cairo’?
import lottie
from lottie.exporters.gif import export_gif
from lottie.parsers.tgs import parse_tgs
def convert_tgs_to_gif(tgs_file, gif_file):
try:
animation = parse_tgs(tgs_file)
export_gif(animation, gif_file, skip_frames=5, dpi=48)
return True
except Exception:
logging.exception("Error occurred while converting TGS to GIF.")
return False
Traceback errors:
Traceback (most recent call last):
File "C:UsersBubunducPycharmProjectstgmain.py", line 11, in <module>
from lottie.exporters.gif import export_gif
File "C:UsersBubunducPycharmProjectstgvenvlibsite-packageslottieexportersgif.py", line 5, in <module>
from .cairo import PngRenderer
ImportError: cannot import name 'PngRenderer' from 'lottie.exporters.cairo' (C:UsersBubunducPycharmProjectstgvenvlibsite-packageslottieexporterscairo.py)
I tried to import this library in different ways, tried to understand the source code
Here the problem is in a completely different library. PngRenderer
requires the cairosvg
library. On windows, it requires libcairo-2.dll. Therefore, the solution to this problem is the correct installation of cairosvg
.
Answer about installing cairosvg
on windows.