Python in Quarto

python
Author

Filip Wästberg

Published

March 3, 2023

I always have trouble with Python environments. To be honest I haven’t really found a setup that I like for it.

Nevertheless, I want to try out some Python in Quarto. So here is a short note on how I went about using conda to do that.

I already had a Python environment that I wanted to use. In the quarto yaml, i.e. the header you can specify the Jupyter kernel you would like to use.

For this post it looks like this:

---
title: "Python in Quarto"
author: "Filip Wästberg"
date: "2023-03-03"
categories: [python]
jupyter: pyds
image: minions.png
---

So I had created an environment based on a conda.yaml file like this:

conda env create -f conda_env.yml

And activate it

conda activate pyds 

The actual yaml file looked like this:

name: pyds
channels:
  - https://repo.anaconda.com/pkgs/snowflake
  - nodefaults
dependencies:
  - python=3.8
  - pip
  - pip:
    # Snowpark
    - snowflake-snowpark-python[pandas]==0.10.0
    # Basics
    - pandas==1.4.3
    - numpy==1.22.3
    # ML
    - scikit-learn==1.1.1
    - lightgbm==3.2.1
    - xgboost==1.5.0
    # Visualization
    ...

However, to be able to use this environment in Quarto I have to register it to jupyter.

I did that like this:

python -m ipykernel install --user --name=pyds

Good luck!