简体   繁体   中英

Python packages required to run RStudio Quarto files in VS Code

I have been trying to run RStudio Quarto script in a fresh Ubuntu 20.04 installation but got into some trouble. Some Python packages that are required to run the simple hello.qmd were not there. I was getting these errors:

MoudleNotFoundError: No module named 'nbclient'

and a second error:

ModuleNotFoundError: No module named 'matplotlib_inline'

The first error was due to I had install the nbclient package in the default Python installation which is python2.7 . This can easily be addressed by configuring multiple Python versions with the help of the command:

sudo update-alternatives --config python

If no Python version shows up then it means you have to configure all your Python versions. This is very well explained at https://www.rosehosting.com/blog/how-to-install-and-switch-python-versions-on-ubuntu-20-04/

Once you have configured all your Python versions, every time that you run sudo update-alternatives --config python , you will be prompted to enter the Python version you want as default. If you have a fresh Ubuntu 20.04, most likely that you have two: Python 2.7 and Python 3.8. Select 3.8 and you will fine. Quarto won't work with Python 2.7

After you have python3 running, install nbclient with: pip install nbclient .

The first error will now pass, but most likely you will get now ModuleNotFoundError: No module named 'matplotlib_inline' . This is because you also need to install the package matplotlib-inline . This is not documented in the installation instructions of Quarto. But easy to fix. Run:

pip install matplotlib-inline

Now, go back to your VS Code, open the command palette and run Quarto: Render , or just type from the terminal:

quarto preview hello.qmd --no-browser --no-watch-inputs

You are done!

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM