I'm trying to write Python code in an Rmarkdown file in RStudio. Generally speaking it works fine. I can write code chunks and knit them perfectly. I can also import and use packages: anything using, say, numpy
or math
runs and knits well.
Despite being able to run and knit code chunks that use other packages, I can't seem to knit the file when it contains chunks that use pandas
. I can run these chunks and obtain the expected output. A minimal example would be simply:
import pandas as pd
which returns the (expected) output:
Python 3.9.4 (/usr/local/bin/python3)
Reticulate 1.20.9000 REPL -- A Python interpreter in R.
(I can also run code chunks using pandas
functions.)
The problem is that, when I knit, I get the error:
Error in py_call_impl(callable, dots$args, dots$keywords) : ModuleNotFoundError: No module named 'pandas' Detailed traceback: File "<string>", line 1, in <module> File "/Library/Frameworks/R.framework/Versions/4.0/Resources/library/reticulate/python/rpytools/loader.py", line 44, in _import_hook level=level Calls: <Anonymous> ... py_capture_output -> force -> <Anonymous> -> py_call_impl Execution halted
I don't understand why I am able to run these code chunks, but not knit them.
Thank you for your help!