1. Ensure you have pyenv installed on your system. On a Unix-based system you can install it using the following command:

    curl https://pyenv.run | bash
    
  2. Now use pyenv to install the specific Python version needed for the Quarto project

    pyenv install <the-python-version>
    
  3. Navigate to your Quarto project directory and set a local Python version for the project

    cd the/path/to/my/quarto-project
    pyenv local <the-python-version>
    

    The last line creates a .python-version file in your project directory, specifying the Python version for this project.

  4. Next, create a virtual environment (.venv) for the local Python version and activate it

    python -m venv .venv
    source .venv/bin/activate
    
  5. Install Python dependencies. These are of course project specific but there are some Python packages required for document compilation and preview with Jupyter to work. Gather these in the file requirements.txt.

    # requirements.txt:
    ipykernel
    PyYAML
    nbformat
    nbclient
    jupyter-cache
    

    Install using pip:

    pip install -r requirements.txt
    
  6. Setup the Jupyter kernel.

    Ensure that the desired virtual environment is active and run

    # install kernel
    python -m ipykernel install --user --name=quarto-proj --display-name "Quarto"
    

    You may check available Jupyter kernels using:

    # available jupyter kernels
    jupyter kernelspec list
    

    You should see a list containing something like

    quarto-proj /Users/martin/Library/Jupyter/kernels/quarto-proj

    The argv entry of the kernel setup kernel.json points to the configured (virtual) environment / executable.

    # inspect kernel setup
    cat /Users/martin/Library/Jupyter/kernels/quarto-proj/kernel.json
    

    In my case, it’s just points to the python 3.10.4 executable in my pyenv path because I executed it while having the global 3.10.4 pyenv version activated, so I see:

    "/Users/martin/.pyenv/versions/3.10.4/bin/python"

    It should point to the path of the virtual environment activated with source .venv/bin/activate.

  7. Configure Quarto to use the Jupyter kernel quarto-proj by adding the following to the yaml header:

    jupyter:
      kernel: "quarto-proj"
    

    If you preview your document using quarto preview <...> you should see the following line in the executing shell:

    Starting quarto-proj kernel...Done

That’s it for now 😊.