我正在使用R markdown和reticulate包。在块中运行简单的2行python代码后,无法使用py $ x函数在R块中使用python变量。我得到以下错误: “错误:找不到对象'py'”
我已经尝试了另一个函数py_to_r来将python对象转换为R,但是即使这样也无法正常工作,因为它会引发一个找不到对象的错误。我还包括python配置:
```{r}
py_config()
```
python: C:\Users\chatsh02\AppData\Local\CONTIN~1\ANACON~1\python.exe
libpython: C:/Users/chatsh02/AppData/Local/CONTIN~1/ANACON~1/python36.dll
pythonhome: C:\Users\chatsh02\AppData\Local\CONTIN~1\ANACON~1
version: 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)]
Architecture: 64bit
numpy: C:\Users\chatsh02\AppData\Local\CONTIN~1\ANACON~1\lib\site-packages\numpy
numpy_version: 1.14.2
python versions found:
C:\Users\chatsh02\AppData\Local\CONTIN~1\ANACON~1\python.exe
C:\Users\chatsh02\AppData\Local\Continuum\anaconda3\python.exe
C:\Users\chatsh02\AppData\Local\Continuum\anaconda3\envs\r-reticulate\python.exe
```{r}
library(reticulate)
use_virtualenv('r-reticulate')
py_available(TRUE)
```
```{python}
a=7
print(a)
```
```{r}
py$a
```
预期结果应该是我应该获得值为7的R变量a实际结果:错误:未找到对象'py'