-
Notifications
You must be signed in to change notification settings - Fork 33
PDF failure #13
Comments
I suspect the issue is you installed the npm packages locally, then ran the Python code from another location that could not access the local install. Try installing the npm packages globally instead:
|
If there are node-related errors, they may be printed in the terminal from which you launched the notebook rather than in the notebook's stdout. |
hmmm, I reinstalled globally like you suggested but am still having trouble. The terminal reads:
|
Ah, it looks like canvas is not correctly configured. Can you try installing the required packages listed at https://www.npmjs.com/package/canvas ? |
We'll need to update the instructions in the README to point to these. |
Also in the invocation we should grab stderr from the subprocess so that it actually prints in the notebook. |
#14 addresses the subprocess/stderr issue. |
I updated the README with instructions on installing requirements with conda. Let me know if that helps |
Thanks! I will give that a try when I can and let you know. |
Well my installation woes continue. Between conda, pip, brew, and the default system python there could be many points of confusion. Let me lay out the facts (as far as I understand them. )
$ which python
/Users/eitanlees/miniconda3/bin/python
$ python --version
Python 3.7.6
$ which npm
/Users/eitanlees/miniconda3/bin/npm
$ npm --version
6.12.0
$ which node
/Users/eitanlees/miniconda3/bin/node
$ node --version
v13.0.0 This leads me to believe I am running the correct python, npm, and node. I followed the instructions in the $ conda install -c conda-forge nodejs
$ npm install -g vega-lite vega-cli canvas The output of the npm WARN npm npm does not support Node.js v13.0.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12.
npm WARN npm You can find the latest version at https://nodejs.org/
/Users/eitanlees/miniconda3/bin/vg2pdf -> /Users/eitanlees/miniconda3/lib/node_modules/vega-cli/bin/vg2pdf
/Users/eitanlees/miniconda3/bin/vg2png -> /Users/eitanlees/miniconda3/lib/node_modules/vega-cli/bin/vg2png
/Users/eitanlees/miniconda3/bin/vg2svg -> /Users/eitanlees/miniconda3/lib/node_modules/vega-cli/bin/vg2svg
/Users/eitanlees/miniconda3/bin/vl2png -> /Users/eitanlees/miniconda3/lib/node_modules/vega-lite/bin/vl2png
/Users/eitanlees/miniconda3/bin/vl2vg -> /Users/eitanlees/miniconda3/lib/node_modules/vega-lite/bin/vl2vg
/Users/eitanlees/miniconda3/bin/vl2svg -> /Users/eitanlees/miniconda3/lib/node_modules/vega-lite/bin/vl2svg
npm WARN [email protected] requires a peer of vega@^5.9.0 but none is installed. You must install peer dependencies yourself.
+ [email protected]
+ [email protected]
+ [email protected]
added 57 packages from 15 contributors and updated 3 packages in 4.775s I would hope now that everything should work. I start up a lab session
and a blank (zero byte) PDF is still produced. It looks like two warnings, then there is the canvas error. I am left in the same position I was in before but now with more errors/warnings. haha. Sorry to unload all these installation problems on you. |
OK – I don't know a lot about this, but I think this indicates some kind of problem with your node-canvas installation, because this was the same error I was seeing before I upgraded canvas. |
What happens if you add |
I tried that as well. $ npm install -g vega vega-lite vega-cli canvas
npm WARN npm npm does not support Node.js v13.0.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12.
npm WARN npm You can find the latest version at https://nodejs.org/
/Users/eitanlees/miniconda3/bin/vg2pdf -> /Users/eitanlees/miniconda3/lib/node_modules/vega-cli/bin/vg2pdf
/Users/eitanlees/miniconda3/bin/vg2png -> /Users/eitanlees/miniconda3/lib/node_modules/vega-cli/bin/vg2png
/Users/eitanlees/miniconda3/bin/vg2svg -> /Users/eitanlees/miniconda3/lib/node_modules/vega-cli/bin/vg2svg
/Users/eitanlees/miniconda3/bin/vl2png -> /Users/eitanlees/miniconda3/lib/node_modules/vega-lite/bin/vl2png
/Users/eitanlees/miniconda3/bin/vl2svg -> /Users/eitanlees/miniconda3/lib/node_modules/vega-lite/bin/vl2svg
/Users/eitanlees/miniconda3/bin/vl2vg -> /Users/eitanlees/miniconda3/lib/node_modules/vega-lite/bin/vl2vg
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
removed 57 packages and updated 4 packages in 5.026s The results in the notebook were the same. No PDF |
Can you get PNG output via Node? |
So I can save PNG but I don't know which method it's using. |
pass |
The PNG fails (blank image) using TypeError: Cannot read property 'getContext' of null
at resize (/Users/eitanlees/miniconda3/lib/node_modules/vega/node_modules/vega-scenegraph/build/vega-scenegraph.js:3607:26)
at CanvasRenderer.prototype$6.resize (/Users/eitanlees/miniconda3/lib/node_modules/vega/node_modules/vega-scenegraph/build/vega-scenegraph.js:3657:5)
at CanvasRenderer.prototype$4.initialize (/Users/eitanlees/miniconda3/lib/node_modules/vega/node_modules/vega-scenegraph/build/vega-scenegraph.js:3235:17)
at CanvasRenderer.prototype$6.initialize (/Users/eitanlees/miniconda3/lib/node_modules/vega/node_modules/vega-scenegraph/build/vega-scenegraph.js:3652:28)
at initializeRenderer (/Users/eitanlees/miniconda3/lib/node_modules/vega/node_modules/vega-view/build/vega-view.js:632:8)
at renderHeadless (/Users/eitanlees/miniconda3/lib/node_modules/vega/node_modules/vega-view/build/vega-view.js:738:12)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async View.renderToCanvas [as toCanvas] (/Users/eitanlees/miniconda3/lib/node_modules/vega/node_modules/vega-view/build/vega-view.js:773:15) Same error. hmmmm |
Yes, same error! Where should I raise the issue? |
Maybe the main vega repo? https://github.com/vega/vega |
Well I am a little embarrassed but I've figured out what was wrong. I had something in my I am happy to report that everything works now! |
Awesome! To better help future users, what was the problematic entry in npmrc? |
A while back I had run
This was the source of all of my problems. It didn't allow the installation to run properly, and as a result, nothing worked. |
I had the same original error when trying to produce .png files, resolved as above by the global npm install
Thanks @jakevdp |
@jakevdp I created a new environment using conda per the README instructions and am experiencing this issue despite having installed
Here is the output of
It would seem like an issue with canvas as you have said above.
The README implies I don't have to do any
Thanks! |
The issue is not with conda, the issue comes from how nodejs is set up on your system. Conda will automatically I don't know npm well enough to suggest where to look, but look for configurations, remove them, and then try installing the tools again. Or, if conda is not working for you, you can install the deps yourself following the installation docs. |
This site lists the possible locations of npmrc settings: https://docs.npmjs.com/configuring-npm/npmrc.html If it's possible to force npm to ignore global settings, we might update the conda recipe to do that. |
The conda environment has an outdated version of conda env filename: altair-saver-test
channels:
- conda-forge
- defaults
dependencies:
- altair_saver
- black
- jupyterlab
- mypy
- pylint
- python=3.7 Conda env# Name Version Build Channel
altair 4.0.1 py_0 conda-forge
altair_data_server 0.4.1 py_0 conda-forge
altair_saver 0.1.0 py_1 conda-forge
altair_viewer 0.2.1 py_0 conda-forge
...
nodejs 13.9.0 hfddbe92_0 conda-forge
...
vega-cli 5.6.0 0 conda-forge
vega-lite-cli 3.4.0 0 conda-forge Notice that the simple_chart = {
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A","b": 28}, {"a": "B","b": 55}, {"a": "C","b": 43},
{"a": "D","b": 91}, {"a": "E","b": 81}, {"a": "F","b": 53},
{"a": "G","b": 19}, {"a": "H","b": 87}, {"a": "I","b": 52}
]
},
"mark": {"type": "bar", "tooltip": True},
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"}
}
}
altair_saver.save(simple_chart, "v4-bar.vg.json") The vega tooltip encoding that is created is: "encode": {
"update": {
"tooltip": {
"value": true
},
... But it should be "encode": {
"update": {
"tooltip": {
"signal": "{\"a\": ''+datum[\"a\"], \"b\": format(datum[\"b\"], \"\")}"
}, Unfortunately this will always happen with a conda env because it will always use the nodejs in the conda environment ahead of the local node installed. So even if you have the correct version of node and |
The vega-cli version could certainly be updated, but I don't think is the cause of the error seen by @eharkins. In particular, the bash commands in #13 (comment) work on my computer with the current conda vega-cli, but result in the reported error for @eharkins. |
Using npm install -g --force vega-lite vega-cli canvas |
@jakevdp on the linked issue you said:
Is that a solution that would work here? I'm just trying to use chart.save('a.png'). If yes, how do I use the selenium saver? |
My problem was resolved with For extra context, the error that brought me to this issue was |
To use the selenium saver, you have to have all the requirements for selenium installed. See https://github.com/altair-viz/altair_saver#selenium |
Makes sense. How do you pick the backend?
… On Apr 17, 2020, at 1:01 AM, Jake Vanderplas ***@***.***> wrote:
To use the selenium saver, you have to have all the requirements for selenium installed. See https://github.com/altair-viz/altair_saver#selenium
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
You can set the backend using the |
(Note that selenium doesn't support PDF output, so it's not an option to solve the original problem in this issue). |
Hi @jakevdp, I suffer from the same issue but I think I understand why now. The TL,DR is that at the moment, conda-forge packages vega-cli and vega-lite-cli are broken for their intended usage. Disclaimer: I am familiar with conda packages building but not very familiar with javascript ecosystem. I did a little bit of reading though about npm and its local and global mode (https://docs.npmjs.com/cli/npm#directories) in particular. Same thing with the alternative javascript package manager yarn: https://classic.yarnpkg.com/en/docs/cli/add/#toc-caveats Install altair, altair_saver with conda in a fresh conda environment:
altair_saver will pull a bunch of packages: altair_data_server, altair_viewer, nodejs, vega-cli and vega-lite-cli as declared dependencies. Once activated, the following command fails:
My understanding of the situation is that the two conda packages Both use the command In other word. we should do it the same way as we do with pip when we create a python conda package: pip installs the python package "globally" in the conda environment. By doing the way it is presently in both conda packages, it is like if vega-cli had its own dependencies isolated from vega-lite-cli and its dependencies because they are installed in different node-modules parent directories. And I am not even sure canvas is installed in one of those 2 node-modules which is the root cause of the error message (see this ticket in vega repo) By removing manually the broken
The command
works perfectly. I will open a PR to both packages on conda forge to fix the issue. |
Awesome - thanks for investigating! |
Hey, just documenting a workaround relating to this issue. I was encountering the same Context: this is happening in a Linux Docker container where I do not have admin rights. Key points:
Steps in solution:
Possible problems you might run into:Missing headers from dependency - probably means jpeg or giflib is missing, or GCC can't find the headers.
Linker can't find libraries from dependency.
|
@jakevdp @rn-c1 I follow your step solution :
I also do :
Then I open a python console and run :
That's return me this error :
I'm on linux ubuntu. Could you please help me. Since days I'm trying to resolve it. I completly uninstall my miniconda environments already. Thanks |
I would try another means of installing node-canvas. The conda-forge route often results in these kinds of problems, and it's not clear to me how to fix it. |
@jakevdp Thank you I manage to save my .png on my computer !!!! I would like also to generate a png in a server. I did the same procedure as on my computer, however I get an error :
I don't understand this kind of error could you please tell me what is the issue ? |
It appears this is the key clue:
You need to also install the |
Ok I finally succeed in saving a plot in
Automattic/node-canvas#1065 (comment) Dependencies for Centos :
Creating a default package.json file at the root of the project if you have this error :
Then run :
https://docs.npmjs.com/creating-a-package-json-file Then run :
Then try saving your plot it should work. |
As a datapoint: I just ran into this problem with However, this may mean that whatever your Relevant conda packages:
|
In case it helps anyone with this same issue: I was able to determine what was wrong with my install by running the example notebook (https://github.com/altair-viz/altair_saver/blob/master/AltairSaver.ipynb) locally. The third code cell will install the files in whatever directory you're in and then you can compare that to the environment in which conda installed the files. Similar to what's been said above, my issue was that some modules were nested. |
maybe your canvas is not installed successful, try comand"npm install -g vega-cli --canvas_binary_host_mirror=https://npm.taobao.org/mirrors/node-canvas-prebuilt/". It helps me |
Since Altair 5.2, the functionality of Altair Saver is now available in Altair via the vl-convert package. Most of the functionality has been available since 5.0, and the main addition in 5.2 was PDF export. See the docs on how to save charts for more details. We are going to archive this repo, so I'm closing all the open issues and PRs before doing so. Try out the new options for saving charts mentioned above and if you run into issues, please open an issue directly in the altair or vl-convert repo. |
Giving the package a run but failed to produce PDFs. The function runs without errors but the pdf produced is blank. I am on macOS 10.12.6
Is there a way I specify the backend or does it know to use nodejs when I ask for a PDF?
I ran
npm install vega-lite vega-cli canvas
which resulted inI am unfamiliar with node so I don't know if that is what should happen.
Here is a small script I ran in a Jupyter notebook for reproducibility.
The text was updated successfully, but these errors were encountered: