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

VS Code can't preview quarto reveal presentation that uses python code sections #342

Closed jpmorr closed 9 months ago

jpmorr commented 9 months ago

I have a revealjs presentation that I've started to create with quarto and in a few slides I have some python code that I want to run, however, when I hit the preview button in VSCode, I get the following warning message:

ERROR: The file cannot be accessed by the system. (os error 1920): stat 'C:\Users\xxx\AppData\Local\Microsoft\WindowsApps\python.exe'

I believe this is a problem with the VS code extension rather than quarto-cli as I can render the document from any powershell terminal by using quarto preview index.qmd and the rendered slides open in a browser window.

If I run quarto check from powershell I get the following output:

PS C:\Users\xxx> quarto check
Quarto 1.4.533
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.533
      Path: C:\Users\xxx\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Tex:  (not detected)

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.11.5 (Conda)
      Path: C:/Users/xxx/Anaconda3/python.exe
      Jupyter: 5.5.0
      Kernels: julia-1.2, julia-1.4, python3, iota

[>] Checking Jupyter engine render....OK

[>] Checking R installation...........OK
      Version: 4.3.2
      Path: C:/PROGRA~1/R/R-4.3.2
      LibPaths:
        - C:/Users/xxx/AppData/Local/R/win-library/4.3
        - C:/Program Files/R/R-4.3.2/library
      knitr: 1.45
      rmarkdown: 2.25

[>] Checking Knitr engine render......OK

Running quarto check from the vscode terminal gives the following output:

quarto check
Quarto 1.4.533
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.533
      Path: C:\Users\xxx\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Tex:  (not detected)

[>] Checking basic markdown render....OK

ERROR: The file cannot be accessed by the system. (os error 1920): stat 'C:\Users\xxx\AppData\Local\Microsoft\WindowsApps\python.exe'

Stack trace:
    at Object.statSync (ext:deno_fs/30_fs.js:363:7)
    at existsSync (file:///C:/Users/xxx/AppData/Local/Programs/Quarto/bin/quarto.js:495:27)
    at getQuartoJupyterCapabilities (file:///C:/Users/xxx/AppData/Local/Programs/Quarto/bin/quarto.js:30543:13)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async jupyterCapabilities (file:///C:/Users/xxx/AppData/Local/Programs/Quarto/bin/quarto.js:30458:28)
    at async file:///C:/Users/xxx/AppData/Local/Programs/Quarto/bin/quarto.js:98419:16
    at async withSpinner (file:///C:/Users/xxx/AppData/Local/Programs/Quarto/bin/quarto.js:75153:16)
    at async checkJupyterInstallation (file:///C:/Users/xxx/AppData/Local/Programs/Quarto/bin/quarto.js:98415:5)
    at async check (file:///C:/Users/xxx/AppData/Local/Programs/Quarto/bin/quarto.js:98280:13)
    at async Command.fn (file:///C:/Users/xxx/AppData/Local/Programs/Quarto/bin/quarto.js:98560:5)

I've tried setting the QUARTO_PYTHON environmental variable in the _environment file to tell quarto which python jupyter to use but that doesn't help.

This is a new problem as I've previously been able to do this without any problem, but I think some recent update may have broken something.

May be related to #341 but this isn't installed from conda, but uses a conda environment.

Oh, I'm running extension version v1.109.0 on windows 10.

jjallaire commented 9 months ago

Using the Windows Store version of Python has lots of problems so should generally be avoided. In order to correctly bind to the Conda environment you want to use the "Python: Select Interpreter" command and then choose that Conda environment. After doing this the Quarto VS Code extension will automatically set QUARTO_PYTHON to this version before running commands in the terminal.

jpmorr commented 9 months ago

Thanks - you are correct about using the "Python: Select Interpreter" to solve the issue. Although, I'm not using the python version from the microsoft store, just plain anaconda install like other machines.