在linux系统、conda环境下配置R软件及R包(内含fatal error: glpk.h: No such file or directory不完全解决办法:(

在第五次因为偷懒想使用本地RStudio跑scRNA-seq数据结果电脑死机蓝屏只能强制重启后——

终于开始配置linux系统服务器下的R了。

本文参考大佬教程:

https://blog.csdn.net/liangjinghui123/article/details/131494540

https://blog.csdn.net/luofunong/article/details/132870880

前情提要:服务器无sudo权限,无法修改默认目录以及各种Path

##linux配置R环境
##查看已有环境
conda info --envs
##新建conda环境
conda create -n R_temporary

中途选择默认yes

##激活环境
source activate R_temporary

##添加channels
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda
conda config --set show_channel_urls yes
conda config --show
##查看R版本信息
conda search r-base
##选择合适的版本安装
conda install r-base=4.3.2

全都选择y

安装成功后(done)进入R:

##进入R
R
##退出R
#q()

 先设置镜像源:

##查看镜像
options()$repos
#    CRAN
#"@CRAN@"
##打开文件
file.edit(file.path("~",".Rprofile"))
##“a”进入编辑状态,写入代码,Esc结束编辑,“:wq”退出
#options("repos"= c(CRAN="https://mirrors.pku.edu.cn/CRAN/","http://mirrors.aliyun.com/CRAN"))
options("repos"=c(CRAN="https://mirrors.pku.edu.cn/CRAN/","https://mirrors.tuna.tsinghua.edu.cn/CRAN/","http://mirrors.aliyun.com/CRAN","https://mirrors.ustc.edu.cn/CRAN/"))
print("已设置北大阿里云镜像")
##退出再重新进入R,查看镜像是否设置好
q()
##进入R
R
##查看镜像
options()$repos
#保证镜像源设置好,装包才能顺利

然后就开始在R中安装BiocManager:

##安装BiocManager:https://www.bioconductor.org/install/
#The current release of Bioconductor is version 3.18; it works with R version 4.3.0.
if (!require("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install(version = "3.18")

在安装BiocManager时也容易遇到千奇百怪的报错:

  URL 'https://bioconductor.org/config.yaml': status was 'Problem with the SSL CA cert (path? access rights?)'

还有:

Bioconductor version cannot be validated; no internet connection?  See
  #troubleshooting section in vignette
Warning messages:
1: In file(con, "r") :
  URL 'https://bioconductor.org/config.yaml': status was 'Couldn't resolve host name'
2: In file(con, "r") :
  URL 'http://bioconductor.org/config.yaml': status was 'Couldn't resolve host name'
Error: Bioconductor version cannot be validated; no internet connection?  See
  #troubleshooting section in vignette

一直报错,无法解决——

试试这样:https://cloud.tencent.com/developer/article/2228246

##让Bioconductor通过联网去验证版本
options(BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS=TRUE)
install.packages("BiocManager")
library(BiocManager)

(其实完全没有装好,但是我装不下去了==)

继续——

正常安装R包:

install.packages("Seurat")#没装上
#version = 5.0.1
library(Seurat)
install.packages("tidyverse")#没装上
library(tidyverse)
install.packages("patchwork")
library(patchwork)
install.packages("ggplot2")
library(ggplot2)
install.packages("clustree")#没装上
library(clustree)
install.packages("cowplot")
library(cowplot)
install.packages("dplyr")
library(dplyr)
install.packages("harmony")
library(harmony) 
BiocManager::install("monocle")#没装上
library(monocle)

可以看到,我一共想安装9个R包,最终安装成功并能顺利library调用的只有5个!!!

经过我千奇百怪的搜索和安装尝试后,报错也千奇百怪:

make: *** [/hpc/data/home/xxx/software/miniconda3/envs/R_temporary/lib/R/etc/Makeconf:193: vendor/cigraph/src/community/optimal_modularity.o] Error 1
ERROR: compilation failed for package ‘igraph’
* removing ‘/hpc/data/home/xxx/software/miniconda3/envs/R_temporary/lib/R/library/igraph’

Warning message:
In install.packages("igraph") :
  installation of package ‘igraph’ had non-zero exit status

Warning: unable to access index for repository https://mirrors.pku.edu.cn/CRAN/src/contrib:
  cannot open URL 'https://mirrors.pku.edu.cn/CRAN/src/contrib/PACKAGES'
Warning: unable to access index for repository https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib:
  cannot open URL 'https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/PACKAGES'
Warning: dependency ‘graph’ is not available

甚至还有缺少编译文件:

In file included from vendor/cigraph/src/community/optimal_modularity.c:32:
vendor/cigraph/src/internal/glpk_support.h:39:10: fatal error: glpk.h: No such file or directory
   39 | #include <glpk.h>
      |          ^~~~~~~~
compilation terminated.
make: *** [/hpc/data/home/xxx/software/miniconda3/envs/R_temporary/lib/R/etc/Makeconf:193: vendor/cigraph/src/community/optimal_modularity.o] Error 1

或者又是缺少依赖库:

Configuration failed to find the harfbuzz freetype2 fribidi library. Try installing:
 * deb: libharfbuzz-dev libfribidi-dev (Debian, Ubuntu, etc)
 * rpm: harfbuzz-devel fribidi-devel (Fedora, EPEL)
 * csw: libharfbuzz_dev libfribidi_dev (Solaris)
 * brew: harfbuzz fribidi (OSX)
If harfbuzz freetype2 fribidi is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a harfbuzz freetype2 fribidi.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: hb-ft.h: No such file or directory
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘textshaping’

/hpc/data/home/xxx/software/miniconda3/envs/R_temporary/bin/../lib/gcc/x86_64-conda-linux-gnu/13.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: cannot find -lxml2: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [/hpc/data/home/xxx/software/miniconda3/envs/R_temporary/lib/R/share/make/shlib.mk:10: xml2.so] Error 1
ERROR: compilation failed for package ‘xml2’
* removing 

但没有sudo权限,根本无法补装依赖库……

在焦虑的驱使下,找到了这篇文章:

https://zhuanlan.zhihu.com/p/585291878

“退出R,使用conda安装”

本小白第一次知道R包还可以用conda安装……

直接开装最难搞也是最有用的Seurat包:

只需静静等待它成功:

进R试试:

注意了,Seurat包首字母可要大写啊!

好好好,又报错:

Error: package or namespace load failed for ‘Seurat’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
 namespace ‘htmltools’ 0.5.6.1 is already loaded, but >= 0.5.7 is required

install一下试试看呢? 

install.packages("htmltools")

Error: package or namespace load failed for ‘Seurat’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
 namespace ‘htmltools’ 0.5.6.1 is already loaded, but >= 0.5.7 is required

仍然报版本错误……那把R包安装路径里的文件夹删掉再重新装呢?

#查看R包安装路径
.libPaths()
#去路径里把htmltools包文件夹删掉
#再次安装
install.packages("htmltools")

继续报错:

ERROR: failed to lock directory ‘/hpc/data/home/xxx/software/miniconda3/envs/R_temporary/lib/R/library’ for modifying
Try removing ‘/hpc/data/home/xxx/software/miniconda3/envs/R_temporary/lib/R/library/00LOCK-htmltools’

再去路径里把00LOCK-htmltools文件夹删掉!

(如果删不掉就重新进入R再删)

删掉后再次安装:

install.packages("htmltools")

然后就很顺利地安装好啦~

再次调用Seurat:(== 你还记得安装htmltools是为了Seurat吗((

成功~

同理,tidyverse和clustree都可以成功安装~

最后看看需要BiocManager安装的monocle:

也找到了大佬的trouble shooting:https://blog.csdn.net/wangyiqi806643897/article/details/125077367

运用一些普适性命令(别搞特殊(

Bioconda上找到要安装的包的对应名字:

conda install -c bioconda bioconductor-monocle

好好好,又报错了:

没有sudo权限的情况下好像确实不好装包…

不装了==累了,就写到这。

  • 33
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
服务器上部署R conda的步骤如下: 1. 首先,切换到目标环境之后,确保你已经重启了RStudio服务器。你可以使用以下命令来检查RStudio服务器的状态: ``` sudo rstudio-server status ``` 如果RStudio服务器正在运行,你可以使用以下命令来停止它: ``` sudo rstudio-server stop ``` 如果你需要重新启动RStudio服务器,可以使用以下命令: ``` sudo rstudio-server restart ``` 2. 确认你的镜像中安装了conda。你可以使用以下命令来查看你的镜像中安装了哪些软件: ``` conda list ``` 3. 如果你需要在R conda环境中安装特定的R,确保你的R版本与该的要求匹配。如果你的R版本不匹配,你可以使用conda来解决这个问题。假设你想安装一个要求R版本为4.3.0的RA,而你的R版本是4.2.0。在这种情况下,你可以使用以下命令创建一个新的R conda环境并指定所需的R版本: ``` conda create -n my_env r=4.3.0 ``` 这将创建一个名为my_env的新环境,并安装R版本为4.3.0。 4. 确认R conda环境中的R路径。你可以使用以下命令来查看R conda环境的R路径: ``` rsession-which-r=/home/dell/miniconda3/envs/my_env/bin/R ``` 这将显示R conda环境的R可执行文件的路径。 总结一下,要在服务器上部署R conda,你需要切换到目标环境并重启RStudio服务器。然后,你可以使用conda来查看镜像中安装的软件和解决安装R时可能出现的各种问题。最后,你可以使用指定的R版本创建一个新的R conda环境,并通过查看R conda环境中的R路径来确认安装。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值