StatsBase文档中有pairwise!函数,为什么安装StatsBase包后,没有这个函数?

问题来源:using MultivariateStats 报错:ERROR: LoadError: UndefVarError: pairwise! not defined。

  • 打开MultivariateStats.jl后发现开头有:using StatsBase: SimpleCovariance, CovarianceEstimator, RegressionModel, AbstractDataTransform, pairwise!
  • 我已经早已安装过StatsBase包,我尝试了一下,加载StatsBase后,却找不到pairwise!函数。
julia> using StatsBase
help?> pairwise!
search:

Couldn't find pairwise!
Perhaps you meant pairs
  No documentation found.

  Binding pairwise! does not exist.
Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Extremes [fe3fe864]:
 Extremes [fe3fe864] log:
 ├─possible versions are: 0.1.0-0.3.0 or uninstalled
 ├─restricted to versions * by an explicit requirement, leaving only versions 0.1.0-0.3.0
 ├─restricted by compatibility requirements with DataFrames [a93c6f00] to versions: 0.1.1-0.3.0 or uninstalled, leaving only versions: 0.1.1-0.3.0
 │ └─DataFrames [a93c6f00] log:
 │   ├─possible versions are: 0.11.7-1.4.4 or uninstalled
 │   ├─restricted to versions * by an explicit requirement, leaving only versions 0.11.7-1.4.4
 │   ├─restricted by compatibility requirements with RData [df47a6cb] to versions: 0.13.0-1.4.4
 │   │ └─RData [df47a6cb] log:
 │   │   ├─possible versions are: 0.5.0-1.0.0 or uninstalled
 │   │   ├─restricted to versions * by an explicit requirement, leaving only versions 0.5.0-1.0.0
 │   │   └─restricted by compatibility requirements with RDatasets [ce6b1742] to versions: 0.5.0-0.8.3
 │   │     └─RDatasets [ce6b1742] log:
 │   │       ├─possible versions are: 0.5.0-0.7.7 or uninstalled
 │   │       ├─restricted to versions * by an explicit requirement, leaving only versions 0.5.0-0.7.7
 │   │       └─restricted by compatibility requirements with DataFrames [a93c6f00] to versions: 0.6.3-0.7.7 or uninstalled, leaving only versions: 0.6.3-0.7.7
 │   │         └─DataFrames [a93c6f00] log: see above
 │   ├─restricted by compatibility requirements with Extremes [fe3fe864] to versions: [0.17.0-0.21.8, 1.0.0-1.4.4]
 │   │ └─Extremes [fe3fe864] log: see above
 │   └─restricted by compatibility requirements with StatsBase [2913bbd2] to versions: 0.19.1-1.4.4 or uninstalled, leaving only versions: [0.19.1-0.21.8, 1.0.0-1.4.4]
 │     └─StatsBase [2913bbd2] log:
 │       ├─possible versions are: 0.24.0-0.33.21 or uninstalled
 │       └─restricted to versions 0.33.21 by an explicit requirement, leaving only versions 0.33.21
 ├─restricted by compatibility requirements with Distributions [31c24e10] to versions: 0.2.0-0.3.0 or uninstalled, leaving only versions: 0.2.0-0.3.0
 │ └─Distributions [31c24e10] log:
 │   ├─possible versions are: 0.16.0-0.25.80 or uninstalled
 │   ├─restricted to versions * by an explicit requirement, leaving only versions 0.16.0-0.25.80
 │   └─restricted by compatibility requirements with StatsBase [2913bbd2] to versions: 0.23.2-0.25.80 or uninstalled, leaving only versions: 0.23.2-0.25.80
 │     └─StatsBase [2913bbd2] log: see above
 └─restricted by compatibility requirements with ClimateTools [4f4ee721] to versions: 0.1.0-0.1.2 — no versions left
   └─ClimateTools [4f4ee721] log:
     ├─possible versions are: 0.9.0-0.23.1 or uninstalled
     ├─restricted to versions * by an explicit requirement, leaving only versions 0.9.0-0.23.1
     └─restricted by compatibility requirements with ClimatePlots [b71d359b] to versions: [0.16.0-0.18.3, 0.20.0-0.22.0]
       └─ClimatePlots [b71d359b] log:
         ├─possible versions are: 0.1.0-0.4.2 or uninstalled
         └─restricted to versions * by an explicit requirement, leaving only versions 0.1.0-0.4.2

这种情况下怎么办? julia包之间的依赖有什么方法处理?

上述问题是因为我要安装ClimateTools包,同时使用Plots包。造成上述报错的原因可能是因为安装ClimateTools会将StatsBase包的版本从0.33.21降到0.32.2,而pairwise!是在0.33.8才添加的。这就造成了找不到pairwise!函数的问题。
同时StatsBase包还造成了一些列其他包(例如Plots)的预编译问题。

大家有什么好的方法解决这种包依赖的问题?

我在 Julia 1.8 版本运行 using MultivariateStats 没有报错,你更新下包的版本,或者贴下 versioninfoMultivariateStats 的版本?


一个极端的方法是将 ~/.julia/ 目录删掉,需要用的包重新安装。

1 个赞

在默认环境下安装了ClimateTools包后各种预编译问题就出来了(见下图)。

Snipaste_2023-01-14_11-11-22

之后我尝试逐个包编译,但只有第一个包成功,之后的包都失败了。我找不到解决方法,使用rm --all删掉了所有的包,需要的包我重新安装。 :sweat_smile: 无法给出当时的版本信息了。

我新建了project环境,在新环境下安装ClimateTools以避免该包造成的依赖问题。目前行得通。

ClimateTools不仅会将StatsBas包的版本从0.33.21降到0.32.2,还会将Plots包从1.38降到1.32。
我觉得这个问题可能是julia生态的一个痛点,不同包的依赖不同,虽然大家都是使用add <package name>来安装包,但是不同的安装顺序都会造成环境不一样。例如,如果先安装ClimateTools,添加StatsBasePlots时,版本就是0.32.2,1.32,而只安装StatsBasePlots,版本就是0.33.21、1.38。

有没有trick来解决类似的问题?

这是我的version:

julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_PKG_SERVER = https://mirrors.bfsu.edu.cn/julia/static
1 个赞

确实有这个问题,复现过程:

]active --temp
]add ClimateTools # 安装过程出现 [2913bbd2] + StatsBase v0.32.2
]add StatsBase # 自动安装 v0.32.2 版本而不是最新版
]add MultivariateStats # 预编译错误
]update
]precompile # 仍然是 MultivariateStats 预编译报错
]st
      Status `/tmp/jl_mYrz3B/Project.toml`
  [4f4ee721] ClimateTools v0.23.1
  [2913bbd2] StatsBase v0.32.2

强行指定版本则导致 ClimeTools 版本后退,并且预编译失败

]add StatsBase@33
]precompile # ClimeTools 预编译报错
]st
      Status `/tmp/jl_mYrz3B/Project.toml`
  [4f4ee721] ClimateTools v0.13.0
  [6f286f6a] MultivariateStats v0.10.0
  [2913bbd2] StatsBase v0.33.21
1 个赞

问题在 ClimateTools,它的版本依赖有很多问题,仓库已经触发了一长串 CompactHelper 的PR。

当前版本有很多兼容性问题:

如果需要同时使用这两个包,建议按 MultivariateStats=>StatsBase=>ClimateTools 的顺序安装,尽管 ClimateTools 会得到比较旧的版本。

Julia 包的版本依赖规则遵循 semantic versioning,这个问题不单是 Julia 导致的,而更多需要包作者的更新维护。包版本的限定规则可以看 Pkg 的文档 6. Compatibility · Pkg.jl

1 个赞