quarto-dev / quarto-nvim

Quarto mode for Neovim
Other
357 stars 13 forks source link

Error E79 when running QuartoPreview and wrong Python being used #143

Open kamransoomro84 opened 3 months ago

kamransoomro84 commented 3 months ago

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.

jmbuhr commented 3 months ago

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 commented 3 months ago

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.

kamransoomro84 commented 3 months ago

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

jmbuhr commented 3 months ago

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

kamransoomro84 commented 3 months ago

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/python@3.12/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 commented 3 months ago

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

jmbuhr commented 3 months ago

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

jmbuhr commented 3 months ago

And do you have jupyter in your environment?

kamransoomro84 commented 3 months ago

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.

jmbuhr commented 3 months ago

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

kamransoomro84 commented 3 months ago

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 commented 3 months ago

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

jmbuhr commented 3 months ago

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?

kamransoomro84 commented 3 months ago

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.

jmbuhr commented 3 months ago

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

jmbuhr commented 3 months ago

oh

kamransoomro84 commented 3 months ago

Also I'm using fish not bash.

kamransoomro84 commented 3 months ago

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 commented 3 months ago

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.