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

quarto-dev/quarto-actions/render@v2 is not using jupyter from conda environment #101

Open
eculler opened this issue Mar 8, 2024 · 2 comments

Comments

@eculler
Copy link

eculler commented Mar 8, 2024

I am trying to publish a site via GitHub Actions. I can render successfully on my machine using quarto cli (quarto render . and quarto publish, and when I do not include any pages with jupyter: python3 specified in the yaml header, my action works. However, when it hits a page with

---
jupyter: python3
---

in the front matter yaml it fails with:

[10/12] pages/01-reproducible-science-tools/open-reproducible-science/03-best-practices.qmd
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.12
  Path: /usr/bin/python3
  Jupyter: (None)
Jupyter is not available in this Python installation.
Install with python3 -m pip install jupyter
There is a environment.yml file in this directory. Is this for a conda env that you need to restore?

I installed and activated my conda environment (which include nbformat, whole environment definition here: https://github.com/cu-esiil-edu/esiil-learning-portal/blob/main/environment.yml) with the following action yaml:

jobs:
  build-deploy:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash -el {0}
    permissions:
      contents: write
    steps:
      ...
      - name: Create and Activate Conda
        uses: conda-incubator/setup-miniconda@v3
        with:
          activate-environment: learning-portal
          environment-file: environment.yml
          auto-activate-base: false

Using shell: bash -el {0} I have found is necessary to get the conda activation to stick for regular shell commands. And I have checked that the environment is activated and available as a kernel to shell commands with the following:

Run jupyter kernelspec list
Available kernels:
  python3    /usr/share/miniconda/envs/learning-portal/share/jupyter/kernels/python3

However, you will notice in the error above that the quarto-actions render action is using /opt/quarto/share/jupyter/jupyter.py as jupyter, and not the version from my environment.

@cderv
Copy link
Collaborator

cderv commented Mar 9, 2024

Thanks a lot for the report. I believe we need some adjustment for Conda environment, as we have done for virtualenv to make sure the activated env works.

As a workaround, I am thinking that if you set QUARTO_PYTHON environment variable in CI jobs to the python version from your learning-portal, Quarto CLI should not do any Python auto-detection and use the right version...

Unless this is an issue only for kernel detection where first occurrence of python3 kernel found is used. 🤔

Anyhow, I am thinking we should detect CONDA_DEFAULT_ENV and if this is set, use that. Can you confirm this env var is set only when you activate a conda environment ?

Thanks!

@eculler
Copy link
Author

eculler commented Mar 15, 2024

Thanks @cderv . I've been using the QUARTO_PYTHON variable, and that works both for my GitHub Actions and also for previewing on my machine.

The following is my output for the CONDA_DEFAULT_ENV variable under different circumstances -- it appears to correspond with the active environment:

(earth-analytics-python) elsa@ESC-Macbook esiil-learning-portal % echo $CONDA_DEFAULT_ENV
earth-analytics-python
(earth-analytics-python) elsa@ESC-Macbook esiil-learning-portal % conda deactivate
(base) elsa@ESC-Macbook esiil-learning-portal % echo $CONDA_DEFAULT_ENV
base
(base) elsa@ESC-Macbook esiil-learning-portal % conda deactivate
elsa@ESC-Macbook esiil-learning-portal % echo $CONDA_DEFAULT_ENV

elsa@ESC-Macbook esiil-learning-portal % 

ratnanil added a commit to Modul-AGI/HS24 that referenced this issue Sep 5, 2024
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

2 participants