测试文档
我的测试文档内容如下:
---
title: "Untitled"
output: html_document
date: "2025-10-31"
---
## R Markdown
```{python}
import torch
A = torch.tensor([[1., -1.], [1., 1.]])
Q, R = torch.linalg.qr(A) # 这行在 R Markdown 文档中运行报错
```
报错信息
knitr 一下错误信息如下:
processing file: Untitled.Rmd
*** caught segfault ***
address 0x0, cause 'invalid permissions'
以上那段 python 代码在控制台运行是没有问题的。
(r-tensorflow) ➜ ~ python
Python 3.13.9 (main, Oct 14 2025, 13:52:31) [Clang 17.0.0 (clang-1700.3.19.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> A = torch.tensor([[1., -1.], [1., 1.]])
>>> Q, R = torch.linalg.qr(A)
>>> Q
tensor([[-0.7071, -0.7071],
[-0.7071, 0.7071]])
>>> R
tensor([[-1.4142e+00, 6.9144e-08],
[ 0.0000e+00, 1.4142e+00]])
我的软件环境
## R version 4.5.1 (2025-06-13)
## Platform: aarch64-apple-darwin20
## Running under: macOS Tahoe 26.0.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: Asia/Shanghai
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.37 R6_2.6.1 fastmap_1.2.0 Matrix_1.7-4
## [5] xfun_0.53 lattice_0.22-7 reticulate_1.44.0 cachem_1.1.0
## [9] knitr_1.50 htmltools_0.5.8.1 png_0.1-8 rmarkdown_2.30
## [13] lifecycle_1.0.4 cli_3.6.5 grid_4.5.1 sass_0.4.10
## [17] jquerylib_0.1.4 compiler_4.5.1 rstudioapi_0.17.1 tools_4.5.1
## [21] evaluate_1.0.5 bslib_0.9.0 Rcpp_1.1.0 yaml_2.3.10
## [25] rlang_1.1.6 jsonlite_2.0.0
我的 Python 环境
> reticulate::py_config()
python: /opt/.virtualenvs/r-tensorflow/bin/python3
libpython: /opt/homebrew/opt/python@3.13/Frameworks/Python.framework/Versions/3.13/lib/python3.13/config-3.13-darwin/libpython3.13.dylib
pythonhome: /opt/.virtualenvs/r-tensorflow:/opt/.virtualenvs/r-tensorflow
virtualenv: /opt/.virtualenvs/r-tensorflow/bin/activate_this.py
version: 3.13.9 (main, Oct 14 2025, 13:52:31) [Clang 17.0.0 (clang-1700.3.19.1)]
numpy: /opt/.virtualenvs/r-tensorflow/lib/python3.13/site-packages/numpy
numpy_version: 2.3.2
NOTE: Python version was forced by RETICULATE_PYTHON