Quarto fails to recognize Python virtual environment #11257
Replies: 3 comments 9 replies
-
Thanks for your post! I just got my setup working so I'll share what I did and maybe that will work for others! View the kernels registered with jupyter:
View the content of the kernel configuration file:
I then created an I think the reason it wasn't working for me previously was because I had configured quarto to look at a different python path than what the kernel was using. I also made sure to specify which kernel I wanted the document code to be executed with:
|
Beta Was this translation helpful? Give feedback.
-
@aronvandepol where did you find mention of this ?
I am not sure this is supposed to work... 🤔
This is how you should be able to configure a
However, this should work; If you activate the venv before running quarto render, the right python version should be used. We described this in https://quarto.org/docs/projects/virtual-environments.html#using-venv We do this in our own CI workflow for testing. Activate the environment, then call |
Beta Was this translation helpful? Give feedback.
-
Could we also make sure that |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I have recently switched to astral UV to manage python for me. I have tried to make it work nicely with Quarto and setup a testing script to do this. I create a virtual env with UV that my quarto project will use. this is located at .venv dir next to the quarto qmd file.
I manually install jupyter using
uv pip install jupyter
to ensure the venv can work with quarto.I have tried the following configs to make quarto pick this up:
quarto render
results in a 'There is an unactivated Python environment in .venv. Did you forget to activate it?' error. Alongside the fact that the packages weren't installed.I then adjusted the _quarto.yml
this calls the prerender script:
export QUARTO_PYTHON=.venv/bin/python
calling
quarto render
with this still results in it not using the environment.I then came across the _environtment file which i tried to setup.
_environment
Again, we get the same error that the python venv is not being used.
When in my terminal I source the venv directly using
source ./venv/bin/activate
and runquarto render
still the same error occurs.Only when i call"
export QUARTO_PYTHON=.venv/bin/python
directly before runningquarto render
will the test file run. The necessary packages get installed first through!uv pip install pandas torch
and the code and renders into a html file without errors.My question is if there is a different way, preferably through Quarto, either the project _quarto.yml or the _environment file to set this? Perhaps I am doing something wrong? The idea is that I don't have to call
export QUARTO_PYTHON=.venv/bin/python
in my terminal everytime before rendering.Any help is appreciated!
Beta Was this translation helpful? Give feedback.
All reactions