类型错误:use() 在导入 matplotlib 时得到了意外的关键字参数“警告" [英] TypeError: use() got an unexpected keyword argument 'warn' when importing matplotlib
问题描述
我正在尝试学习 R markdown/notebook 来实现 R 和 Python 的代码块.我可以使用R达到合理的标准,但是我是Python的新手.我已经将 R markdown 下载到 R studio 并按照提示下载 miniconda 并这样做了.
I am attempting to learn R markdown / notebook to implement chunks of code which are R and Python. I can use R to a reasonable standard, but I am new to Python. I have downloaded R markdown to R studio and followed the prompts to download miniconda and did so.
我想作一个基本图,看看它是否有效.
I wanted to make a basic plot to see if it is working.
我点击插入一个新的Python块"
I click 'insert a new Python chunk'
然后将以下代码复制并粘贴到"Python块"中,该代码在使用Spyder环境的Python中可以正常工作.
Then copy and paste the following code into a 'Python chunk', which worked fine in Python using the Spyder environment.
import matplotlib.pyplot as plt
x = [2, 4, 6, 8, 10, 12]
y = [1, 3, 5, 6, 9, 15]
plt.plot(x, y)
plt.show()
返回以下错误:
Error in py_call_impl(callable, dots$args, dots$keywords) :
TypeError: use() got an unexpected keyword argument 'warn'
我在 r 块中使用以下内容安装了 matplotlib:
I had installed matplotlib using the following in an r chunk:
library(reticulate)
py_install("matplotlib")
我尝试使用以下方法将此块粘贴到Python块和R块中:
I have tried pasting this chunk into a Python chunk and an R chunk with:
{r,engine='python'}
但无济于事.我看不到有人有相同的错误,也看不到指定如何从Python导入的指南,这似乎都表明这些块是开箱即用的.如果我缺少明显的东西,我深表歉意.我确保已卸载所有其他版本的Python.任何建议都将不胜感激,因为我有一天希望能够在此东西中集成Python,R和bash脚本!
But to no avail. I can't see anyone having the same error or a guide specifying how to be able to import from Python, it all seems to show these chunks working straight out of the box. Apologies if I am missing something glaringly obvious. I have made sure all other versions of Python are uninstalled. Any advice would be greatly appreciated, as I one day hope to be able to integrate Python, R and bash scripts in this thing!
会话信息:
Windows 10, R version 3.6.3 (2020-02-29), R Studio Version 1.2.5001. R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.28 reticulate_1.16
loaded via a namespace (and not attached):
[1] compiler_3.6.3 Matrix_1.2-18 tools_3.6.3 rappdirs_0.3.1
[5] Rcpp_1.0.4.6 grid_3.6.3 jsonlite_1.6.1 xfun_0.9
[9] lattice_0.20-38
推荐答案
使用网状纹理和matplotlib时,我遇到了完全相同的错误.
I had the exact same error when using reticulate and matplotlib.
我通过降级matplotlib版本来修复它,例如:
I fixed it by downgrading my matplotlib version, e.g.:
pip install matplotlib==3.2
您可以通过运行 pip freeze
并找到 matplotlib 条目来验证 matplotlib 是否已降级.它应该看起来像 matplotlib==3.2.0
.(也许可以尝试从r中执行此操作,因此可以确保您使用的是正确的python安装).
You can verify that matplotlib has been downgraded by running pip freeze
and finding the matplotlib entry. It should look like matplotlib==3.2.0
. (maybe try doing this from r, so you can be sure that you're working with the correct python installation).
我认为这个问题是由于在最新版本的 matplotlib 中从 matplotlib 函数中删除了warn"参数引起的,而 R/reticulate 假定该函数的行为较旧.
I think this issue is caused by the 'warn' parameter being removed from a matplotlib function in recent versions of matplotlib, and R/reticulate assumes the older behaviour of the function.
这篇关于类型错误:use() 在导入 matplotlib 时得到了意外的关键字参数“警告"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!