Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render_to_png creates all black pictures #2

Closed
rsommer opened this issue Jun 21, 2012 · 18 comments
Closed

render_to_png creates all black pictures #2

rsommer opened this issue Jun 21, 2012 · 18 comments

Comments

@rsommer
Copy link

rsommer commented Jun 21, 2012

Hi,

whenever i use render_to_png everything is black. If i output the svg and load it in inkscape, everything is black, too. The objects are all there, but it seems like no styles are applied. (pygal via pip, tested with pycairo 1.8.8 and py2cairo 1.10.0 on python 2.7)

Thanks!

@SimonSapin
Copy link
Member

Is the SVG also black if you open it a web browser?
I suppose you installed CairoSVG in order to get PNG output. CSS support is optional in CairoSVG, you’ll also need to install tinycss and cssselect.

Admittedly this should be better documented.

SimonSapin added a commit that referenced this issue Jun 21, 2012
@rsommer
Copy link
Author

rsommer commented Jun 21, 2012

Installed tinycss and cssselect and now everything is just fine.

@sebhoa
Copy link

sebhoa commented Dec 12, 2014

Same kind of trouble... all is black :( svg and i can't create png
OS : Yosemite
Python : 3.4.2 (that's why I can't install pycairo and so I can't generate png file)

@SimonSapin
Copy link
Member

Same kind of trouble... all is black :( svg

In the SVG also black when opened in a web browser?

and i can't create png
OS : Yosemite
Python : 3.4.2 (that's why I can't install pycairo and so I can't generate png file)

pycairo for python 3 is a thing. But so is cairocffi, which might be easier to install: http://pythonhosted.org/cairocffi/ CairoSVG (that Pygal uses to render PNG) supports either. Also don’t forget to install tinycss and cssselect, as mentioned above.

@sebhoa
Copy link

sebhoa commented Dec 12, 2014

Hi,
Thx for helping. Unfortunatly after success installations of cairocffi,
cairosvg, tinycss and cssselect, the render_to_png method produces the
following error:

Traceback (most recent call last):

File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/cairosvg/surface/init.py",
line 25, in

import cairocffi as cairo

File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/cairocffi/init.py",
line 41, in

cairo = dlopen(ffi, *CAIRO_NAMES)

File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/cairocffi/init.py",
line 34, in dlopen

return ffi.dlopen(names[0])  # pragma: no cover

File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/cffi/api.py",
line 118, in dlopen

lib, function_cache = _make_ffi_library(self, name, flags)

File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/cffi/api.py",
line 411, in _make_ffi_library

backendlib = _load_backend_lib(backend, libname, flags)

File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/cffi/api.py",
line 400, in _load_backend_lib

return backend.load_library(name, flags)

OSError: cannot load library libcairo.2.dylib: dlopen(libcairo.2.dylib, 2):
image not found

Seb

2014-12-12 13:49 GMT+04:00 Simon Sapin notifications@github.com:

Same kind of trouble... all is black :( svg

In the SVG also black when opened in a web browser?

and i can't create png
OS : Yosemite
Python : 3.4.2 (that's why I can't install pycairo and so I can't generate
png file)

pycairo for python 3 is a thing. But so is cairocffi, which might be
easier to install: http://pythonhosted.org/cairocffi/ CairoSVG (that
Pygal uses to render PNG) supports either. Also don’t forget to install
tinycss and cssselect, as mentioned above.


Reply to this email directly or view it on GitHub
#2 (comment).

@SimonSapin
Copy link
Member

Try installing cairo with HomeBrew, MacPorts, or whatever your favorite package manager is.

@sebhoa
Copy link

sebhoa commented Dec 12, 2014

cairo installed via MacPorts, successfully... indeed my png is black :(

@sebhoa
Copy link

sebhoa commented Dec 13, 2014

Hi,
To solve problem of missing library I finally use:
export DYLD_FALLBACK_LIBRARY_PATH=“some path”

But black pictures are all there!
And finaly I found that all works fine if I execute my script from the home directory only. If I change directory pygal produces black pictures.

On Dec 12, 2014, at 20:06, Simon Sapin notifications@github.com wrote:

Try installing cairo with HomeBrew, MacPorts, or whatever your favorite package manager is.


Reply to this email directly or view it on GitHub #2 (comment).

@corelon
Copy link

corelon commented Aug 13, 2015

Hi I installed tinycss and cssselect but I am still getting black images. I can view the svg in the browser but the resulting png is black and the svg if seen outside a browser is also black. Please help.

@corelon
Copy link

corelon commented Aug 13, 2015

Just a quick update. I am using ipython notebook generally. Apparently when trying to run the code through the notebook the png appears black. When I transfer the python code to an external file and run it it works fine. Any ideas as to why?

@paradoxxxzero
Copy link
Member

Are you sure both tinycss and cssselect are installed in your notebook environment ?

@frutik
Copy link

frutik commented Mar 22, 2016

Same story here. Ubuntu, all libraries listed in comments to this issues were installed. And still black picture instead of the chart. SVG is OK

@liZe
Copy link
Member

liZe commented Mar 22, 2016

Getting black PNG when the SVG file is OK means that the CSS is not correctly applied.

With CairoSVG (used by render_to_png), you have to install cssselect and tinycss, and SVG will be correctly rendered as PNG.

Some other SVG renderers are known to fail at rendering Pygal graphs. librsvg (used by Gnome applications for example) will render images as black, it's a known bug in librsvg.

So:

  • If you use render_to_png and get a black image, it means that the cssselect and tinycss libraries are not available for a reason or another. You can try to render the SVG first, then convert to SVG using CairoSVG and check if there's anything wrong in the logs. You also have to check that the libraries are not installed only for you and / or in a virtual environment if the tool you use is launched by another user (@corelon that's maybe the cause of your problem).
  • If you use another tool, for example nautilus or eye of gnome, then the rendering is broken because of librsvg.

@RebornHuan
Copy link

pip install lxml

@sfdye
Copy link

sfdye commented Aug 14, 2017

pip install tinycss
pip install cssselect

solved my problem

@sergani
Copy link

sergani commented Jan 20, 2018

pip install tinycss
pip install cssselect
pip install lxml

solved my problem - Centos 6, Python 2.7.14

@Rieselhilfe
Copy link

I had the same problem and none of the above solutions worked for me. I wanted to embed the svgs directly into html code via a cgi-script, so I generated the svg in a folder where a style.css for this website was stored. I could solve my problem by renaming that file, because apparently pygal detects and uses files named "style.css" in the same directory automatically. In my case, this broke the svg, which was the reason for the all black picture. I don't know if this is unexpected behaviour but at least I can't find anything about this automatic detection in the documentation and if it is desired it seems to produce corrupted svg-files.

@rootVIII
Copy link

oooo same problem here. I had it working just fine in python3 virtualenv. But the boss/server requires python2. So now with a new virtualenv and everything reinstalled (including lxml, cairosvg, cssselect, and tinycss) there is nothing but black. It doesn't matter if it's a .svg, .png, or browser render.

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests