如何使用Julia的PackageCompiler为PlotStats构建快速启动环境?

4

我希望在重启计算机后能够使用'DataFrames,CSV,StatsPlots'包,我正在尝试使用PackageCompiler,但是README或帮助文档很难理解。

using using PackageCompiler
syso, sys = compile_incremental(:DataFrames,:CSV,:StatsPlots)

我不想破坏系统镜像,因此一开始我没有使用 "force=true" 选项。然后它显示错误信息:

...
Resolving package versions... 
ERROR: LoadError: Unsatisfiable requirements detected for package WinRPM [c17dfb99]:
 WinRPM [c17dfb99] log:                                                                                                                                             
 ├─possible versions are: [0.3.3, 0.4.0-0.4.3] or uninstalled                     
 ├─restricted by compatibility requirements with PackageCompiler [9b87118b] to versions: [0.3.3, 0.4.0-0.4.3]                                                       
  └─PackageCompiler [9b87118b] log: 
    ├─possible versions are: [0.5.0-0.5.1, 0.6.0-0.6.5] or uninstalled
    └─restricted to versions * by an explicit requirement, leaving only versions [0.5.0-0.5.1, 0.6.0-0.6.5]
 ├─restricted by compatibility requirements with Compat [34da2185] to versions: 0.4.3 or uninstalled, leaving only versions: 0.4.3
  └─Compat [34da2185] log:
    ├─possible versions are: [1.0.0-1.0.1, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.5.0-1.5.1, 2.0.0, 2.1.0, 2.2.0, 3.0.0, 3.1.0, 3.2.0] or uninstalled
    └─restricted to versions 3.2.0 by an explicit requirement, leaving only versions 3.2.0
 └─restricted by compatibility requirements with HTTPClient [0862f596] to versions: uninstalled  no versions left
   └─HTTPClient [0862f596] log:
     ├─possible versions are: 0.2.1 or uninstalled
     └─restricted by compatibility requirements with Compat [34da2185] to versions: uninstalled
       └─Compat [34da2185] log: see above
1个回答

2

看起来使用 PackageCompilerX 是可行的。首先,软件包的版本非常敏感,需要正确的版本才能让一切正常运作。

这里是我用于 Julia 1.3.1 的两个测试环境:

  • Debian:apt -t unstable install julia libjulia-dev
  • ArchLinux:pacman -S julia

检查 Julia 的版本(PackageCompilerX 只适用于 1.3.1 及以上版本)

julia> versioninfo()
Julia Version 1.3.1
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU @ 2.20GHz

添加PackageCompilerX以及您想要绘制的所有包到存储库中。

pkg> add https://github.com/KristofferC/PackageCompilerX.jl
pkg> status
Status `~/.julia/environments/v1.3/Project.toml`
...

将系统的 Project.toml 复制到当前目录以自定义开发环境,使用编辑器(这里是vim)来删除一些无法编译或不需要的软件包。

shell> rm Project.toml
shell> cp ~/.julia/environments/v1.3/Project.toml .
shell> vim Project.toml

激活本地包环境

julia> using PackageCompilerX
pkg> activate .
pkg> status  # double check all package which you want have installed
    Status `~/prj/julia/Project.toml`
  [336ed68f] CSV v0.5.22
  [a93c6f00] DataFrames v0.20.0
  ...

在Julia提示符中自动生成符号数组
s=split(read("Project.toml", String),"\n")
pkgs=Symbol[]
for i in s
  if (length(i) > 0) && !(i[1] in ['[','#'])
    push!(pkgs, Symbol(split(i," ")[1]))
  end
end

展示 pkgs
julia> pkgs
10-element Array{Symbol,1}:
 :CSV
 :DataFrames
 ...

编译它并将其输出到"dev.so"

julia> create_sysimage(pkgs, sysimage_path="dev.so")

退出Julia,并通过以下方式重新启动Julia:

julia -J dev.so

对这两种启动方法进行基准测试并比较结果:

time julia -q -e 'using Plots,UnicodePlots; unicodeplots(); display(plot(sin))'
# result: 35.175s
time julia -J dev.so -q -e 'using Plots,UnicodePlots; unicodeplots(); display(plot(sin))'
# result: 15.2365s

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接