gpt4 book ai didi

python - 安装r包后rpy2错误

转载 作者:太空狗 更新时间:2023-10-30 00:18:49 25 4
gpt4 key购买 nike

我正在尝试使用名为“huge”的 r 包。我在 rpy2 中遇到问题,因为我正在尝试安装此软件包,代码使用以下代码运行良好:

import rpy2.robjects.packages as rpackages

# import R's utility package
utils = rpackages.importr('utils')

# select a mirror for R packages
utils.chooseCRANmirror(ind=1) # select the first mirror in the list

packnames = ('huge')

# R vector of strings
from rpy2.robjects.vectors import StrVector

# Selectively install what needs to be install.
# We are fancy, just because we can.
names_to_install = ['huge']
if len(names_to_install) > 0:
utils.install_packages(StrVector(names_to_install))

只有警告,告诉我:

/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: also installing the dependency ‘igraph’


warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: trying URL 'https://cloud.r-project.org/src/contrib/igraph_1.1.2.tar.gz'

warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: Content type 'application/x-gzip'
warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: length 3376958 bytes (3.2 MB)

warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: =
warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning:

warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: downloaded 3.2 MB


warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: trying URL 'https://cloud.r-project.org/src/contrib/huge_1.2.7.tar.gz'

warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: length 2946819 bytes (2.8 MB)

warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: downloaded 2.8 MB


warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning:
warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: The downloaded source packages are in
‘/tmp/RtmpOb6GhL/downloaded_packages’
warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: Updating HTML index of packages in '.Library'

warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: Making 'packages.html' ...
warnings.warn(x, RRuntimeWarning)
/home/johnzhou/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/rinterface/__init__.py:145: RRuntimeWarning: done

warnings.warn(x, RRuntimeWarning)

但是,当我尝试使用以下方式加载包时:

rpy2.robjects.packages.importr("huge")

我收到一条错误消息,它告诉我:

RRuntimeError                             Traceback (most recent call last)
<ipython-input-104-843fb8da3355> in <module>()
----> 1 rpy2.robjects.packages.importr("huge")

~/anaconda3/envs/python35/lib/python3.5/site-packages/rpy2/robjects/packages.py in importr(name, lib_loc, robject_translations, signature_translation, suppress_messages, on_conflict, symbol_r2python, symbol_check_after, data)
451 if _package_has_namespace(rname,
452 _system_file(package = rname)):
--> 453 env = _get_namespace(rname)
454 version = _get_namespace_version(rname)[0]
455 exported_names = set(_get_namespace_exports(rname))

RRuntimeError: Error in loadNamespace(name) : there is no package called ‘huge’

有人可以帮我解决这个问题吗?

谢谢

最佳答案

您是否尝试过检查安装包的库?

几天前我遇到了同样的问题,我按照这些步骤操作1. 在 R 中使用 .libPaths() 检查库路径2. 尝试使用 install.packages('package name') 在 R 控制台中安装包3. 检查包是否安装在您作为上述步骤 1 获得的路径中。4. 如果它安装在不同的库中,则只需将包从该目录复制到 .libPaths() 库即可。

R 尝试在默认位置查找库,您只需将包放在默认库路径中(使用 .libPaths() 找到它)

希望对你有帮助

关于python - 安装r包后rpy2错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46377695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com