quarto-dev / quarto-actions

GNU General Public License v2.0
221 stars 51 forks source link

'quarto-actions/render@v2' fails after multiple renders with `ModuleNotFoundError: No module named 'nbformat'` #80

Closed richelbilderbeek closed 1 year ago

richelbilderbeek commented 1 year ago

Dear Quarto developers,

I enjoy using quarto-actions/render@v2, yet it fails for unknown reasons when one calls it multiple times.

In my case now, the first and second use of quarto-actions/render@v2 both work fine, whereas the third fails, with unexpected errors as ModuleNotFoundError: No module named 'nbformat' and Jupyter is not available in this Python installation. The qmd file being rendered does not contain me using nbformat nor Jupyter, ~~but it does use the R library reticulate (which calls Python).
I guess that that is the problem, I will check now and leave this Issue as it is.~~ and it is always the third render being the problem.

Below, I show:

I hope you can help me fix this.

Thanks and cheers, Richel

The GHA log of the passing second call to render

> Run quarto-dev/quarto-actions/render@v2
> Run echo $(which chromium-browser)
/usr/bin/chromium-browser
[0527/145930.525595:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.
[0527/145930.547001:WARNING:sandbox_linux.cc(393)] InitializeSandbox() called with multiple threads in process gpu-process.
> Run if [ "pdf" == "" ]; then

processing file: tdd_lecture.qmd
1/17                  
2/17 [unnamed-chunk-1]
3/17                  
4/17 [unnamed-chunk-2]
5/17                  
6/17 [unnamed-chunk-3]
7/17                  
8/17 [unnamed-chunk-4]
9/17                  
10/17 [unnamed-chunk-5]
11/17                  
12/17 [unnamed-chunk-6]
13/17                  
14/17 [unnamed-chunk-7]
15/17                  
16/17 [unnamed-chunk-8]
17/17                  
output file: tdd_lecture.knit.md

pandoc 
  to: latex
  from: markdown+emoji
  output-file: tdd_lecture.tex
  standalone: true
  pdf-engine: xelatex
  variables:
    graphics: true
    tables: true
  default-image-extension: pdf

metadata
  documentclass: scrartcl
  classoption:
    - DIV=11
    - numbers=noendperiod
  papersize: letter
  header-includes:
    - '\KOMAoption{captions}{tableheading}'
  block-headings: true
  title: TDD
  author: Richèl Bilderbeek
  editor: visual

running xelatex - 1
  This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

running xelatex - 2
  This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

Output created: tdd_lecture.pdf

The failing third call call to render

> Run quarto-dev/quarto-actions/render@v2
> Run echo $(which chromium-browser)
/usr/bin/chromium-browser
[0527/145958.260342:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.
[0527/145958.285170:WARNING:sandbox_linux.cc(393)] InitializeSandbox() called with multiple threads in process gpu-process.
> Run if [ "pdf" == "" ]; then
  if [ "pdf" == "" ]; then
    quarto render testing/testing_lecture/testing_lecture.qmd
  else
    quarto render testing/testing_lecture/testing_lecture.qmd --to pdf
  fi
  if [ -f "_book" ]; then
    echo "QUARTO_OUTPUT=_book" >> $GITHUB_ENV
  elif [ -f "_site" ]; then
    echo "QUARTO_OUTPUT=_site" >> $GITHUB_ENV
  fi
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    GITHUB_PAT: ***
    BUNDLE_EXT: linux-amd64.deb
    R_LIBS_USER: /home/runner/work/_temp/Library
    TZ: UTC
    _R_CHECK_SYSTEM_CLOCK_: FALSE
    NOT_CRAN: true
    QUARTO_PRINT_STACK: true

Starting python3 kernel...Traceback (most recent call last):
  File "/opt/quarto/share/jupyter/jupyter.py", line 21, in <module>
    from notebook import notebook_execute, RestartKernel
  File "/opt/quarto/share/jupyter/notebook.py", line 17, in <module>
    import nbformat
ModuleNotFoundError: No module named 'nbformat'
Python 3 installation:
  Version: 3.10.6
  Path: /usr/bin/python3
  Jupyter: (None)

Jupyter is not available in this Python installation.
Install with python3 -m pip install jupyter

ERROR: Error
    at renderFiles (file:///opt/quarto/bin/quarto.js:86657:30)
    at async render (file:///opt/quarto/bin/quarto.js:90679:21)
    at async Command.fn (file:///opt/quarto/bin/quarto.js:90854:32)
    at async Command.execute (file:///opt/quarto/bin/quarto.js:8437:13)
    at async quarto (file:///opt/quarto/bin/quarto.js:127540:5)
    at async file:///opt/quarto/bin/quarto.js:127558:9
Error: Process completed with exit code 1.

GitHub Actions script

name: Build PDFs

on:
  push:
  pull_request:

jobs:
  build_pdfs:

    runs-on: ubuntu-latest
    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

    steps:
      - uses: actions/checkout@v2

      - uses: quarto-dev/quarto-actions/setup@v2
        with:
          tinytex: true

      - uses: r-lib/actions/setup-r@v2

      - name: Install R packages
        run: install.packages(c("testthat", "reticulate", "rmarkdown"))
        shell: Rscript {0}

      - uses: quarto-dev/quarto-actions/render@v2
        with:
          to: pdf
          path: tdd/tdd_lecture/netiquette.qmd

      - uses: quarto-dev/quarto-actions/render@v2
        with:
          to: pdf
          path: tdd/tdd_lecture/tdd_lecture.qmd

      - uses: quarto-dev/quarto-actions/render@v2
        with:
          to: pdf
          path: testing/testing_lecture/testing_lecture.qmd
richelbilderbeek commented 1 year ago

It had nothing to do with reticulate, another qml file was used to render third, and that one failed as well. ~The problem seems to be the third qml file render, regardless of the contents of the qml file.~

The problem seems to in a (Python-only) qmd file. I will create a reprex at https://github.com/richelbilderbeek/quarto_actions_issue_80...

cderv commented 1 year ago

You are using Python in your qmd file: https://github.com/UPPMAX/programming_formalisms/blob/fc410729e37d49a99f45838c704e2da3744540f9/testing/testing_lecture/testing_lecture.qmd#L49-L53

but the action script you copied above did not have Python setup. Now I see a commented python setup: https://github.com/UPPMAX/programming_formalisms/blob/42059e31421eb2fa4ce2ae7cde3f5b5e5becb915/.github/workflows/build_pdfs.yaml#L21-L30

If you are using Python in a project, you need to configure Python to use with Quarto (which requires Jupyter): https://quarto.org/docs/computations/python.html#installation

Did you try this ?

It would be the same with reticulate that requires a python setup.

richelbilderbeek commented 1 year ago

@cderv thanks for this awesome answer, I'll try it, confirm if it works yes/no, then close this Issue if that worked.

Thanks :+1:

richelbilderbeek commented 1 year ago

Confirmed to work! Thanks again to @cderv! Closing this Issue :-)