安装monocle3包报错ERROR: compilation failed for package ‘sf’系列问题

一、安装monocle3包

monocle3 是一个用于分析单细胞转录组数据的 R 包。它提供了强大的工具来进行细胞轨迹分析、细胞类型标注以及其他高级单细胞数据分析功能。下面是如何在你的系统中安装 monocle3 包的详细步骤

这有一个参考,如何安装monocle3,BiocManager::install("monocle3")问题解决
如何安装monocle3,BiocManager::install("monocle3")问题解决 (qq.com)

install.packages("monocle3")
BiocManager::install("monocle3")

Error in library(monocle3) : there is no package called ‘monocle3’

这个错误提示说明 monocle3 包尚未成功安装。我们可以通过确保安装过程无误来解决这个问题。以下是详细的步骤:

1. 安装必要的依赖包
首先,确保你已经安装了 remotes 包,因为我们将使用它来安装 monocle3 包。

install.packages("remotes")

2. 使用 remotes 安装 monocle3
接下来,使用 remotes 包从 GitHub 安装 monocle3 包:

remotes::install_github("cole-trapnell-lab/monocle3")
这将从 GitHub 下载和安装最新版本的 monocle3 包。

3. 安装 sf 包的依赖项

如果你在安装 monocle3 之前遇到 sf 包的依赖问题,请确保你已经安装了 sf 包及其所有依赖项。以下是在 Ubuntu 系统上常见的步骤:

如果你在 R 控制台中,可以使用 system() 函数来安装必要的系统依赖项

system("sudo apt-get update")
system("sudo apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev")

安装 R 包
install.packages("units", dependencies = TRUE)
install.packages("sf", dependencies = TRUE, type = "source")

4. 安装 monocle3 所有依赖包
确保安装 monocle3 之前所需的所有依赖包:

install.packages(c("BiocManager", "devtools"))
BiocManager::install(c("BiocGenerics", "DelayedArray", "DelayedMatrixStats", "limma", "S4Vectors", "SingleCellExperiment", "SummarizedExperiment", "batchelor"))

5. 再次尝试安装 monocle3
在安装完所有依赖包之后,再次尝试安装 monocle3:

remotes::install_github("cole-trapnell-lab/monocle3")

6. 加载并验证 monocle3
安装完成后,加载 monocle3 包并验证它是否成功安装:
library(monocle3)

在安装sf包步骤又报错:

install.packages("units", dependencies = TRUE)
install.packages("sf", dependencies = TRUE, type = "source")

error: ‘ret’ was not declared in this scope
  713 |  return ret;
      |         ^~~
make: *** [/usr/lib/R/etc/Makeconf:200: gdal.o] Error 1
ERROR: compilation failed for package ‘sf’
* removing ‘/usr/local/lib/R/site-library/sf’
ERROR: dependency ‘sf’ is not available for package ‘leafem’
* removing ‘/usr/local/lib/R/site-library/leafem’
ERROR: dependency ‘sf’ is not available for package ‘leafpop’
* removing ‘/usr/local/lib/R/site-library/leafpop’
ERROR: dependency ‘sf’ is not available for package ‘lwgeom’
* removing ‘/usr/local/lib/R/site-library/lwgeom’
ERROR: dependency ‘sf’ is not available for package ‘stars’
* removing ‘/usr/local/lib/R/site-library/stars’
ERROR: dependencies ‘sf’, ‘lwgeom’, ‘stars’ are not available for package ‘tmaptools’
* removing ‘/usr/local/lib/R/site-library/tmaptools’
ERROR: dependencies ‘leafem’, ‘leafpop’, ‘sf’ are not available for package ‘mapview’
* removing ‘/usr/local/lib/R/site-library/mapview’
ERROR: dependencies ‘tmaptools’, ‘sf’, ‘stars’, ‘leafem’ are not available for package ‘tmap’
* removing ‘/usr/local/lib/R/site-library/tmap’

从错误日志中可以看出,编译 sf 包时出现了 ‘ret’ was not declared in this scope 的错误。这通常意味着编译器找不到某个变量的定义,可能是由于缺少某些头文件或库版本不兼容的问题。

以下是一些可能的解决方案:

1.更新系统库
确保所有相关的系统库(GDAL、GEOS、PROJ)都已更新到最新版本。

对于 Ubuntu/Debian 系统
首先,添加必要的 PPA 来获取最新版本的 GDAL、GEOS 和 PROJ:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update 

然后安装或更新相关库:
sudo apt-get install -y gdal-bin libgdal-dev libgeos-dev libproj-dev libudunits2-dev libsqlite3-dev libcurl4-openssl-dev libssl-dev build-essential

2.手动编译和安装 GDAL 和 PROJ
如果系统包管理器提供的版本较旧,可以考虑手动编译和安装最新版本的 GDAL 和 PROJ。

安装 PROJ
wget https://download.osgeo.org/proj/proj-7.2.1.tar.gz
tar -xvf proj-7.2.1.tar.gz
cd proj-7.2.1
./configure
make
sudo make install

安装 GDAL
sh
wget https://download.osgeo.org/gdal/3.2.1/gdal-3.2.1.tar.gz
tar -xvf gdal-3.2.1.tar.gz
cd gdal-3.2.1
./configure
make
sudo make install

3.设置 R 环境变量
确保 R 可以找到正确的编译器和库路径:

Sys.setenv("PKG_CONFIG_PATH" = "/usr/local/lib/pkgconfig:/usr/lib/pkgconfig")
Sys.setenv("LD_LIBRARY_PATH" = "/usr/local/lib:/usr/lib")

4.重新安装 units 包
有时候 units 包的问题会导致 sf 包无法安装。先尝试重新安装 units 包。
install.packages("units", dependencies = TRUE, type = "source")


5.手动安装 sf 包
手动下载 sf 包的源代码并安装:
wget https://cran.r-project.org/src/contrib/sf_1.0-0.tar.gz
在 R 控制台中手动安装:
install.packages("sf_1.0-0.tar.gz", repos = NULL, type = "source", verbose = TRUE)

也试了

安装install.packages("sf")报错解决办法.checking GDAL: checking whether PROJ
安装install.packages("sf")报错解决办法.checking GDAL: checking whether PROJ | 生信圆桌 (tebteb.cc)

仍然报错,哭了

error: ‘ret’ was not declared in this scope
  713 |  return ret;
      |         ^~~

最后遇见了

remotes::install_github(repo = "r-spatial/sf")

成功了

Downloading GitHub repo r-spatial/sf@HEAD
Running `R CMD build`...
* checking for file ‘/tmp/RtmpMNsu0s/remotes10c4f632fb6/r-spatial-sf-a07adc6/DESCRIPTION’ ... OK
* preparing ‘sf’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* running ‘cleanup’
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘sf_1.0-18.tar.gz’
Installing package into ‘/cloud/lib/x86_64-pc-linux-gnu-library/4.4’
(as ‘lib’ is unspecified)
* installing *source* package ‘sf’ ...
** using staged installation
configure: CC: gcc
configure: CXX: g++ -std=gnu++17
checking for gdal-config... /usr/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 3.0.4
checking GDAL version >= 2.0.1... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for gdal.h... yes
checking GDAL: linking with --libs only... yes
checking GDAL: /usr/share/gdal/pcs.csv readable... no
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available for running:... yes
configure: GDAL: 3.0.4
configure: pkg-config proj exists, will use it
configure: using proj.h.
configure: PROJ: 6.3.1
checking PROJ: checking whether PROJ and sqlite3 are available for linking:... yes
checking for geos-config... /usr/bin/geos-config
checking geos-config usability... yes
configure: GEOS: 3.8.0
checking GEOS version >= 3.4.0... yes
checking for geos_c.h... yes
checking geos: linking with -L/usr/lib/x86_64-linux-gnu -lgeos_c... yes
configure: Package CPP flags:   -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include
configure: Package LIBS: -lproj   -L/usr/lib -lgdal -L/usr/lib/x86_64-linux-gnu -lgeos_c
configure: creating ./config.status
config.status: creating src/Makevars
** libs
using C++ compiler: ‘g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0’
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c bbox.cpp -o bbox.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c gdal.cpp -o gdal.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c gdal_geom.cpp -o gdal_geom.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c gdal_read.cpp -o gdal_read.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c gdal_read_stream.cpp -o gdal_read_stream.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c gdal_utils.cpp -o gdal_utils.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c gdal_write.cpp -o gdal_write.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c geos.cpp -o geos.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c hex.cpp -o hex.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c mdim.cpp -o mdim.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c ops.cpp -o ops.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c polygonize.cpp -o polygonize.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c proj.cpp -o proj.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c proj_info.cpp -o proj_info.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c raster2sf.cpp -o raster2sf.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c sfc-sfg.cpp -o sfc-sfg.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c signed_area.cpp -o signed_area.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c stars.cpp -o stars.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c wkb.cpp -o wkb.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include    -fpic  -g -O2   -c zm_range.cpp -o zm_range.o
g++ -std=gnu++17 -shared -L/opt/R/4.4.1/lib/R/lib -L/usr/local/lib -o sf.so RcppExports.o bbox.o gdal.o gdal_geom.o gdal_read.o gdal_read_stream.o gdal_utils.o gdal_write.o geos.o hex.o mdim.o ops.o polygonize.o proj.o proj_info.o raster2sf.o sfc-sfg.o signed_area.o stars.o wkb.o zm_range.o -lproj -L/usr/lib -lgdal -L/usr/lib/x86_64-linux-gnu -lgeos_c -L/opt/R/4.4.1/lib/R/lib -lR
installing to /cloud/lib/x86_64-pc-linux-gnu-library/4.4/00LOCK-sf/00new/sf/libs
** R
** demo
** inst
** byte-compile and prepare package for lazy loading
in method for ‘dbWriteTable’ with signature ‘"PostgreSQLConnection","character","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘dbDataType’ with signature ‘"PostgreSQLConnection","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘coerce’ with signature ‘"Spatial","sf"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"Spatial","sfc"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sf","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sfc","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"XY","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"crs","CRS"’: no definition for class “CRS”
in method for ‘coerce’ with signature ‘"sgbp","sparseMatrix"’: no definition for class “sparseMatrix”
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (sf)

再安装monocle3包就可以了。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,386评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,142评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,704评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,702评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,716评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,573评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,314评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,230评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,680评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,873评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,991评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,706评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,329评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,910评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,038评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,158评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,941评论 2 355

推荐阅读更多精彩内容