Using Homebrew Python with Blogdown
By default, Blogdown uses the system Python installation. To tell Blogdown to use a different version of Python, e.g., Python 3 installed via Homebrew, one needs to configure a different engine in Knitr:
knitr::opts_chunk$set(engine.path = list(python = '/usr/local/bin/python3'))
I include this line in my ~/.Rprofile
. Now you can test to ensure that it is using the specified version of Python:
import sys
print(sys.version)
## 3.9.5 (default, May 4 2021, 03:36:27)
## [Clang 12.0.0 (clang-1200.0.32.29)]
print(sys.executable)
## /usr/local/opt/python@3.9/bin/python3.9