quarto-nvim icon indicating copy to clipboard operation
quarto-nvim copied to clipboard

Error E79 when running QuartoPreview and wrong Python being used

Open kamransoomro84 opened this issue 1 year ago • 20 comments

I have two issues. I have setup my quarto configuration by copying quarto.lua from the kickstarter configuration. When I run QuartoPreview I get the following error:

E79: Cannot expand wildcards

The other issue is that the plugin appears to be using the wrong python environment. I have a custom environment in venv that I activate before starting nvim. But when I quite nvim I get a bunch of error messages like this:

Starting python3 kernel...Traceback (most recent call last):
    3   File "/Applications/quarto/share/jupyter/jupyter.py", line 21, in <module>
    4     from notebook import notebook_execute, RestartKernel
    5   File "/Applications/quarto/share/jupyter/notebook.py", line 15, in <module>
    6     from yaml import safe_load as parse_string
    7 ModuleNotFoundError: No module named 'yaml'
    8 Python 3 installation:
    9   Version: 3.10.12 (Conda)
   10   Path: /opt/homebrew/Caskroom/mambaforge/base/bin/python
   11   Jupyter: (None)
   12
   13 Jupyter is not available in this Python installation.
   14 Install with conda install jupyter

This is the wrong python environment but I cannot figure out how to get it to use the right one.

EDIT: I should mention that I am on Mac.

kamransoomro84 avatar Aug 06 '24 03:08 kamransoomro84

Neovim's integrated terminal, which is used in to run quarto preview (https://neovim.io/doc/user/various.html#%3Aterminal), does so inside of your default shell. If you have allowed conda to modify the startup of your default shell, e.g. your bashrc, zshrc or fishrc file, to automatically activate the base environment on startup it will do so and change the available python.

jmbuhr avatar Aug 09 '24 09:08 jmbuhr

You can add auto_activate_base: false to your .condarc file or disable conda entirely by removing the eval "$($CONDA_PREFIX/bin/conda shell.bash hook)" line from your bashrc.

jmbuhr avatar Aug 09 '24 09:08 jmbuhr

Does the plugin require r to be installed even if I'm not using it in my qmd file?

kamransoomro84 avatar Aug 09 '24 10:08 kamransoomro84

No, quarto-cli can be installed independently of R (https://quarto.org/)

jmbuhr avatar Aug 09 '24 10:08 jmbuhr

I'm still getting the error after uninstalling conda:

Starting python3 kernel...Traceback (most recent call last):
  File "/Applications/quarto/share/jupyter/jupyter.py", line 21, in <module>
    from notebook import notebook_execute, RestartKernel
  File "/Applications/quarto/share/jupyter/notebook.py", line 15, in <module>
    from yaml import safe_load as parse_string
ModuleNotFoundError: No module named 'yaml'
Python 3 installation:
  Version: 3.12.4
  Path: /opt/homebrew/opt/[email protected]/bin/python3.12
  Jupyter: (None)

Jupyter is not available in this Python installation.
Install with python3 -m pip install jupyter

I can confirm that my custom environment is activated when I start nvim.

kamransoomro84 avatar Aug 09 '24 10:08 kamransoomro84

Just to be clear this is not by custom environment. How do I get the plugin to use it?

kamransoomro84 avatar Aug 09 '24 10:08 kamransoomro84

Does quarto preview use the correct environment when you call it directly?

jmbuhr avatar Aug 09 '24 10:08 jmbuhr

And do you have jupyter in your environment?

jmbuhr avatar Aug 09 '24 10:08 jmbuhr

Yes to both questions. I have been using the custom environment with quarto in vscode. I guess as a work around I can launch quarto preview from the terminal and use the plugin that way but it would be nice to have the neovim command working.

kamransoomro84 avatar Aug 09 '24 10:08 kamransoomro84

Is there a difference between quarto check outside of nvim and :tabedit term://quarto check from nvim?

jmbuhr avatar Aug 09 '24 10:08 jmbuhr

Yes. Outside of nvim the command locates my venv python. Within neovim it locates my default python. In both cases the python environment was first activated. I think this might be the issue.

kamransoomro84 avatar Aug 09 '24 10:08 kamransoomro84

I can confirm that if I open a neovim terminal, activate the environment and run quarto preview, it works.

kamransoomro84 avatar Aug 09 '24 10:08 kamransoomro84

right, so in this case, after disabling conda, it is the binaries from brew that get added to the path again when the rc file is sourced again from inside of nvim. Can you design your rc file in such a way that it doesn't do that?

jmbuhr avatar Aug 09 '24 10:08 jmbuhr

I'll have to think about how that can be done. The method suggested in the reddit post of using $SHLVL doesn't work. In my case SHLVL is 1 both within and without nvim.

kamransoomro84 avatar Aug 09 '24 10:08 kamransoomro84

For example, the proposed solution in the reddit post of using $SHLVL seems rather elegant.

jmbuhr avatar Aug 09 '24 10:08 jmbuhr

oh

jmbuhr avatar Aug 09 '24 10:08 jmbuhr

Also I'm using fish not bash.

kamransoomro84 avatar Aug 09 '24 10:08 kamransoomro84

I just compared my $PATH variable within and without nvim, with the virtual environment activated in both cases.

It actually doesn't add on the brew path in nvim. It only adds on its local mason bin path. The venv path is still the second path in my $PATH.

kamransoomro84 avatar Aug 09 '24 11:08 kamransoomro84

Weirdly, if I run :tabedit term://which python it correctly locates my venv python. But if I run :tabedit quarto check it shows my default brew python.

kamransoomro84 avatar Aug 09 '24 11:08 kamransoomro84

edit: in response to the second issue regarding the python kernel

I have spent hours and hours trying to figure out why this was happening to me, and think I have found a fix (though not sure how future proof it is). I had python 3.13 installed with homebrew which has problems working with jupyterlab /jupyter. I followed this stack exchange thread to revert to python 3.9 and all of the sudden everything works. I may upgrade to python 3.10 since i'm seeing that's one of the more popular versions, but at least 3.9 works.

not sure if it's relevant but I have a .venv created with UV that i open before opening quarto, and also spent hours trying to figure out why the venv wasn't being used by neovim when running :QuartoPreview, though it does recognize the python packages installed in the venv, so i guess that was never the issue, and it was my python version.

hope this helps, stoked to use quarto!

DrewRichard7 avatar Mar 16 '25 19:03 DrewRichard7