当我尝试用简单的python代码主干编织.Rmd文件时,它失败了。但是,当我在[0.0 ... 1.0]
包中使用repl_python()
函数时,所有python代码都可以在控制台命令行中顺利运行。
键入reticulate
时,它返回py_available()
。
因此,我认为我的Python配置没有错误。我无法弄清楚我的R Markdown文件出了什么问题。
TRUE
结果证明:
---
title: "Untitled"
author: "Malcolm"
date: "2019/11/21"
output: html_document
---
```{r setup}
library(reticulate)
#conda_create("r-reticulate") # I created a new conda environment
#conda_install("r-reticulate", "scipy") # and I installed all python libraries I need.
#conda_install("r-reticulate", "pandas")
#conda_install("r-reticulate", "seaborn")
use_condaenv("r-reticulate")
py_module_available('pandas')
```
```{python}
import numpy as np
import seaborn as sns
from scipy.stats import f
from scipy.stats import boxcox
r = f.rvs(30, 30, size=500)
np.random.seed(1234)
transformed,fitted_lambda = boxcox(r)
print('lambda=',fitted_lambda)
sns.distplot(r, rug=True,color='green')
sns.distplot(transformed, rug=True)
```
P.S。当我使用Quitting from lines 34-37 (reticulate.Rmd)
Error in py_call_impl(callable, dots$args, dots$keywords) : ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.8 from "C:\PROGRA~1\R\R-36~1.1\bin\x64\Rterm.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.17.3" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible
Calls: <Anonymous> ... py_capture_output -> force -> <Anonymous> -> py_call_impl
停止执行
检查所需的软件包时,它们都返回py_module_available('libraryname')
。尽管我使用FALSE
,但是它不起作用。有人可以使用您的R Markdown成功地编织出我上面的简单Python代码吗?
我尝试了conda_install("r-reticulate", "libraryname")
的CRAN和开发版本,但都失败了。
我的R环境是:
reticulate
sessionInfo()
答案 0 :(得分:0)
我的经验是,如果您遇到相同的问题,请使用git并回滚到以前的提交版本,该问题将得到解决。 :D
git reset