如何在 Databricks 中安装 python 包 'rpy2'?

How to install python package 'rpy2' in Databricks?

我正在尝试在 Databricks 中安装和使用 pymer4 包功能,这也需要安装 rpy2。在集群中的库下我可以安装它们,它甚至说 "Installed",但是当我尝试导入它们时它会出错,就好像它没有正确安装一样。在本地系统中完美运行。

from pymer4.test_install import test_install

错误是:


ImportError: No module named 'pandas.core.dtypes'
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<command-2946392196605768> in <module>()
----> 1 from pymer4.test_install import test_install

/databricks/python/lib/python3.5/site-packages/pymer4/__init__.py in <module>()
      6            "__version__"]
      7 
----> 8 from .models import Lmer, Lm
      9 from .simulate import (easy_multivariate_normal,
     10                        simulate_lm,

/databricks/python/lib/python3.5/site-packages/pymer4/models.py in <module>()
      2 import rpy2.robjects as robjects
      3 from rpy2.robjects.packages import importr
----> 4 from rpy2.robjects import pandas2ri
      5 import rpy2
      6 from copy import copy

/databricks/python/lib/python3.5/site-packages/rpy2/robjects/pandas2ri.py in <module>()
     14 from pandas.core.series import Series as PandasSeries
     15 from pandas.core.index import Index as PandasIndex
---> 16 from pandas.core.dtypes.api import is_datetime64_any_dtype
     17 import pandas
     18 import numpy

ImportError: No module named 'pandas.core.dtypes'

能够解决我自己的问题。无非是pymer4包的依赖包版本问题。 将以下软件包的版本更改为 pymer4 发布日期之前的最新版本并且有效:

matplotlib==3.0.2
pandas==0.23.4
rpy2==2.9.4
tzlocal