Linux系统使用PackageCompiler.jl报错

为了解决julia脚本每次运行需要编译导致速度慢的问题,我使用了PackageCompiler这个包编译器。我在windows系统,julia1.4.1中时可以正常使用这个package的,效果良好。但当我在Linux系统,julia1.4.1中使用这个package创建系统镜像时出现了error或是直接卡在了创建的命令中。由于我暂时没有重现这个error,所以直接贴之前error的截图了:

现在我运行创建系统镜像的命令则是卡在下面这步:

image

软件及系统版本信息为:

julia> versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_PKG_SERVER = https://mirrors.bfsu.edu.cn/julia/static

太糊了,看不起,还是贴代码吧 :yum:

julia> using PackageCompiler

julia> create_sysimage(:JuMP, sysimage_path="/home/yy/sys_test.so", precompile_execution_file="/home/yy/test.jl")
[ Info: PackageCompiler: creating system image object file, this might take a while...
ERROR: failed process: Process(`/home/yy/julia-1.4.2/bin/julia --color=yes --startup-file=no --cpu-target=native --sysimage=/home/yy/julia-1.4.2/lib/julia/sys.so --project=/home/yy/.julia/environments/v1.4 --output-o=/tmp/jl_iO8qhD.o -e 'Base.reinit_stdio()
@eval Sys BINDIR = ccall(:jl_get_julia_bindir, Any, ())::String
Base.init_load_path()
Base.init_depot_path()
using JuMP
# This @eval prevents symbols from being put into Main
@eval Module() begin
    PrecompileStagingArea = Module()
    for (_pkgid, _mod) in Base.loaded_modules
        if !(_pkgid.name in ("Main", "Core", "Base"))
            eval(PrecompileStagingArea, :(const $(Symbol(_mod)) = $_mod))
        end
    end
    precompile_statements = String[]
        append!(precompile_statements, readlines("/tmp/jl_nVx9jH"))

    for statement in sort(precompile_statements)
        # println(statement)
        try
            Base.include_string(PrecompileStagingArea, statement)
        catch
            # See julia issue #28808
            @debug "failed to execute $statement"
        end
    end
end # module
empty!(LOAD_PATH)
empty!(DEPOT_PATH)
'`, ProcessSignaled(9)) [0]

Stacktrace:
 [1] pipeline_error at ./process.jl:525 [inlined]
 [2] run(::Cmd; wait::Bool) at ./process.jl:440
 [3] run at ./process.jl:438 [inlined]
 [4] create_sysimg_object_file(::String, ::Array{String,1}; project::String, base_sysimage::String, precompile_execution_file::Array{String,1}, precompile_statements_file::Array{String,1}, cpu_target::String, script::Nothing, isapp::Bool) at /home/yy/.julia/packages/PackageCompiler/xtztx/src/PackageCompiler.jl:292
 [5] create_sysimage(::Symbol; sysimage_path::String, project::String, precompile_execution_file::String, precompile_statements_file::Array{String,1}, incremental::Bool, filter_stdlibs::Bool, replace_default::Bool, cpu_target::String, script::Nothing, base_sysimage::Nothing, isapp::Bool) at /home/yy/.julia/packages/PackageCompiler/xtztx/src/PackageCompiler.jl:423
 [6] top-level scope at REPL[2]:1

我在另一个Linux系统上重复了一样的工作,得到了一样的报错,这是报错的内容。

/home/yy/test.jl的文件内容是?

using JuMP
m = Model()
就是使用了JuMP,只有两行代码。

不幸的是,我在我的电脑上并没有重现此问题。

julia> create_sysimage(:JuMP, sysimage_path="sys_test.so", precompile_execution_file="test.jl")
[ Info: PackageCompiler: creating system image object file, this might take a while...

julia> versioninfo()
Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, ivybridge)
Environment:
  JULIA_NUM_THREADS = 4

jerrywang@jerrywang-PC:~$ cat /proc/version
Linux version 5.3.0-3-amd64 (debian-kernel@lists.debian.org) (gcc version 8.3.0 (Debian 8.3.0-6)) #1 SMP deepin 5.3.15-6apricot (2020-04-13)

不过,我一开始尝试的时候,遇到了路径错误的问题。即create_sysimage函数中的路径为只能为相对路径(=默认工作路径+你写的路径)。在linux中,一般默认工作路径为~

如果你没有修改默认工作路径,你可以把test.jl依然放入~/中,然后尝试

create_sysimage(:JuMP, sysimage_path="sys_test.so", precompile_execution_file="test.jl")

谢谢你的回复,我尝试和你一样把路径改为相对路径,但还是出现了同样的ERROR。这很奇怪,因为我在远程使用两台Linux系统的服务器时都出现了同样的问题,但却没有在你那里重现。

你的文件是从晕倒(windows)拷贝过来的吗?

试一下

pip install dos2unix
dos2unix YOUR_file.jl

我的jl脚本确实是从windows拷贝过去的。不过我使用apt install dos2unix;dos2unix test.jl;转换后,还是出现了一样的问题。并且我使用直接在Linux中用vim写的test.jl,还是有一样的问题。

请问你系统的内存有多大?我刚刚在GitHub上看到一个类似的问题,提到该问题可能是由内存不足导致的。我在Windows系统下使用create_sysimage,发现内存占用峰值达到了2.5GB,而我的Linux VPS最大内存只有1GB,很可能就是内存不足的原因。

有可能吧,我是本地的linux,内存大一点,12G。1核1G的VPS用来做计算有点太小了哈哈哈哈。白嫖google colab多香