quarto-dev / quarto

Quarto open-source scientific and technical publishing system
https://quarto.org
GNU Affero General Public License v3.0
315 stars 26 forks source link

Quarto installed via conda can't see jupyterlab and does not work with the vscode extension #341

Open joelostblom opened 9 months ago

joelostblom commented 9 months ago

It seems like quarto installed via conda does not recognize jupyter/jupyterlab installation in the same environment. See screenshot:

image

I have seen that I can set the QUARTO_PYTHON env variable but I would like quarto to automatically use the python version in the conda env where quarto is installed (ie read path instead of setting its own python version)


It also seems like VScode cannot detect this version of quarto although I have specified the full path in the settings:

image

When I try to render, it says "quarto not found".

image

I can work around this issue by launching vscode from a terminal where the conda env has already been activated but that seems to be defeating the purpose of having the setting to set the explicit quarto path

cderv commented 9 months ago

cc @mfisher87 in case you encountered this type of issue in the past with the conda Quarto package

For reference, Quarto conda package lives there: https://github.com/conda-forge/quarto-feedstock

mfisher87 commented 9 months ago

Quarto + Jupyter in conda env

I'm not seeing this problem. Is it occurring entirely without the involvement of VSCode?

[✓] Checking Python 3 installation....OK
      Version: 3.12.0 (Conda)
      Path: /home/robatt/.local/share/miniconda3/envs/quarto/bin/python
      Jupyter: 5.3.2
      Kernels: python3

If this is occurring outside of a VSCode context, please create a new issue over on the feedstock repo and we'll work together to try and figure it out :)

If you're using a Bourne-incompatible shell (i.e. export not supported), then read on. There's an open issue for this on the feedstock repo, and unfortunately I'm not yet ready to try the fix because it's undocumented. I've opened a request to update the docs, but waiting for explicit confirmation before starting work on the docs.

VSCode

I know very little about VSCode, I apologize.

This could be related to this sticky issue on our feedstock: https://github.com/conda-forge/quarto-feedstock/issues/30

What I'd naively expect from VSCode is that it only needs to know which conda environment to activate, and then from there $PATH gives it the info it needs to find quarto. Seeing that the full path to Quarto is being passed to VSCode is a smell something is wrong (to me).

If VSCode is not activating your Quarto environment in the supported way (using a Bourne-compatible shell), then when it tries to run the Quarto script at its exact path, the correct envvars won't be set and it will fail. It looks like you have Quarto installed correctly outside the VSCode context, so this is unfortunately my best guess. VSCode may simply be reporting "Quarto is not installed" because it's trying a quarto check under the hood, and that's returning non-zero. Do you have VSCode set up in a way that it's aware of your conda environment (I don't really know what this looks like)?

Anyone know how to check what's actually happening under VSCode's covers?

joelostblom commented 9 months ago

Thanks @mfisher87 ! I do see this outside vscode, and my shell is zsh so the export command exists. I opened https://github.com/conda-forge/quarto-feedstock/issues/34 as a follow up for the jupyter part.

For the vscode part, my understanding is that I only need to set up the path to the quarto executable (that's what the quarto docs say at least) and not do anything else with my conda env. For jupyternotebooks, vscodes provides a mechanism to associate a conda kernel with the notebook, but I don't see that quarto provides anything similar. I tried setting the path in the options do the base dir of the environment, but I get an error message saying it needs to be the path to the quarto executable.

joelostblom commented 9 months ago

One more note is that although the terminal inside (and outside) vscode does not find jupyter, I can render quarto docs and execute python chunks as long as vscode is launched from a terminal where I have activated the conda environment first. This workflow is OK for me, but it would be great if it could be documented in the documentation instead of using the quarto path setting which stands out as the relevant option to configure right now since that's what's encountered first in the UX.

mfisher87 commented 9 months ago

For the vscode part, my understanding is that I only need to set up the path to the quarto executable (that's what the quarto docs say at least) and not do anything else with my conda env.

I believe the Quarto dev team doesn't have very many Conda users, so if there are caveats dealing with how Quarto+VSCode+Conda work together, I think it's on folks like us to help contribute that information to the docs. Would you feel comfortable opening a PR to improve the docs?

Are you using a Quarto extension in VSCode or is this a built-in feature? If the former, perhaps we should loop another GitHub repository in to this discussion; it may be that the extension needs to be able to be conda-aware like the Jupyter extension you mentioned.

joelostblom commented 9 months ago

I'm happy to PR the docs if it is confirmed that the "correct" way to use quarto with conda is that we shouldn't use the path setting in the UI and instead must launch vscode from within a conda environment.

I am using the official quarto extension for VS Code. I believe this is the repo to file issues for that extension, but happy to open it somewhere else if that is not the case

mfisher87 commented 9 months ago

I am using the official quarto extension for VS Code. I believe this is the repo to file issues for that extension, but happy to open it somewhere else if that is not the case

Good point. I thought I was in the quarto-cli repo :laughing:

mfisher87 commented 9 months ago

Circling back from investigation in https://github.com/conda-forge/quarto-feedstock/issues/34:

The issue is jupyter_core (accidentally?) removing the __version__ attribute from the root import in 3.6.x: https://github.com/jupyter/jupyter_core/issues/384

cderv commented 9 months ago

About this jupyter_core change we did an adaptation in Quarto recently

Regarding documentation, current about conda is at https://quarto.org/docs/projects/virtual-environments.html#using-conda

But this is about conda environment for python and jupyter and not directly the Conda installed Quarto. Though both are related probably. Activating conda environment to run the tools install in it seems a common practice though 🤔

We always welcome PR to the documentation (https://github.com/quarto-dev/quarto-web)

mfisher87 commented 9 months ago

About this jupyter_core change we did an adaptation in Quarto recently

https://github.com/quarto-dev/quarto-cli/issues/7964 (https://github.com/quarto-dev/quarto-cli/commit/ccfdc52daeae74c66e4d6715ef5bbbcf2ccac05f)

Yes, found that! Can that fix be backported to 1.3.x?

Regarding documentation, current about conda is at https://quarto.org/docs/projects/virtual-environments.html#using-conda

But this is about conda environment for python and jupyter and not directly the Conda installed Quarto. Though both are related probably. Activating conda environment to run the tools install in it seems a common practice though 🤔

I was more wondering if there are any gotchas with the VSCode-Conda-Quarto combination that should be called out in the Quarto-VSCode docs? I think based on what we've found, that's not the solution, the solution is to get this issue resolves.

joelostblom commented 9 months ago

I made a follow up PR in https://github.com/quarto-dev/quarto-web/pull/959

Activating conda environment to run the tools install in it seems a common practice though 🤔

I don't think it is for VSCode. The most common workflow I see is to launch vscode from the system's program launcher/start menu and then activate different conda environments via "Select Python Interpreter" for both python scripts and jupyter notebooks. It is convenient to launch VS this way since you have access to all conda kernels and can have multiple files open with different kernels. This workflow still works with quarto documents, but it only switches the python packages and not the quarto executable. I think this actually makes sense since we would want to hook up different kernels to use with quarto without having quarto installed in each one of them.

The most confusing part to me currently is that there is an option in the VSCode extension to set the quarto path and that option does not seem to work (at least not for quarto installed in conda envs); if this option worked then VSCode could be launched from the program launcher and then still see quarto wherever it was installed on the system, which to me is the expected behavior and how I have worked with other vscode installations that allow specification to a binary file (e.g. the neovim extension).