我正在尝试在r studio中运行网格化和导入python模块(特别是R-markdown)。R代码块似乎完成了预期的工作(即安装python模块),并且似乎没有产生任何错误,但是python代码块似乎没有完成预期的工作(即导入已安装的包)。它不会产生任何输出(或错误),这有点奇怪。
我尝试了新安装的reticulate,使用了新安装的R Studio的devtools版本,并使用了完整的conda路径而不是名称,但似乎都不起作用。我不知道出了什么问题。我也已经在stackoverflow中搜索了各种答案,并尝试了各种建议,但似乎都不起作用)。此外,我还安装了miniconda和python ( python包和脚本运行得很好)。如果有人能帮上忙,那就太好了。
(对格式表示歉意,最后的反引号表示代码块的末尾没有正确显示)
## R code chunk```{r}library("reticulate")#devtools::install_github("rstudio/reticulate")conda_create("my_project_env")py_install(packages = c("numpy","pandas","scikit-learn","matplotlib","seaborn","statsmodels"))py_install(packages = c("IPython"))# Either of these seem to "work" for installation#conda_install(packages = c("numpy","pandas","scikit-learn","matplotlib","seaborn","statsmodels"))#conda_install(packages = c("IPython"))conda_list()use_condaenv("my_project_env")The python code chunk below seems to "run" but does not produce any output or errors (such as the python module could not be found) and I am unable to use the modules.
```javascriptPython代码块
```{python}
# Main packages
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns发布于 2020-12-01 10:43:33
似乎解决方案是以以下方式在r studio代码块中运行导入:
library("reticulate")
conda_create("my_project_env")
py_install(packages = c("numpy","pandas","scikit-learn","matplotlib","seaborn","statsmodels"))
conda_list()
use_condaenv("full_path_to_python_for my_project_env")
py_run_string('import numpy as np')
py_run_string('import pandas as pd')
py_run_string('import matplotlib.pyplot as plt')
py_run_string('import seaborn as sns')在那里,我可以在python代码块中运行python函数,而不会出现问题。
https://stackoverflow.com/questions/65082487
复制相似问题