conda 安裝 rpy2 版本不匹配問題解決方法
問題描述:Anaconda3(python 3.8) 安裝 rpy2 (R 4.0.4)時嘗試使用 conda install rpy2 安裝,但是報錯如下:
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- rpy2 -> python[version='2.7.*|3.5.*|3.6.*|>=2.7,<2.8.0a0|>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|3.4.*']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for. When python appears to the right, that indicates that the thing on the left is somehow not available for the python version you are constrained to. Note that conda will not change your python version to a different minor version unless you explicitly specify that.

解決辦法:
1、下載 rpy2 之前,先確認在當前 python 和 R 版本下所支持的 rpy2 版本,版本查詢路徑如下:https://rpy2.github.io/doc.html
下拉查詢對應的 rpy2 版本分別有 3.5.x,3.4.x 等,分別點擊,以 3.5.x 為例點擊進入,進入其 Background ,獲取到其支持的 python 以及 R 版本為:



2、發現 rpy2 3.5.x 即滿足需求,這里下載 3.5.1版本,方法如下:pip install rpy2==3.5.1

之后在 spyder(Python 3.8)調用 rpy2,import rpy2.robjects as robjects 可以順利調用 !


浙公網安備 33010602011771號