Julia 的 GR_jll包已被安装且可using:
julia> using GR_jll
但是在using Plots和using GR的时候报错GR_jll not defined
。Plots和GR都是用到GR_jll的包。Plots的报错:
[ Info: Precompiling Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80]
ERROR: LoadError: InitError: UndefVarError: GR_jll not defined
Stacktrace:
[1] __init__()
@ GR.GRPreferences F:\Julia-1.8.2\packages\packages\GR\mf3ag\src\preferences.jl:50
[2] _include_from_serialized(pkg::Base.PkgId, path::String, depmods::Vector{Any})
@ Base .\loading.jl:831
[3] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt64)
@ Base .\loading.jl:1039
[4] _require(pkg::Base.PkgId)
@ Base .\loading.jl:1315
[5] _require_prelocked(uuidkey::Base.PkgId)
@ Base .\loading.jl:1200
[6] macro expansion
@ .\loading.jl:1180 [inlined]
[7] macro expansion
@ .\lock.jl:223 [inlined]
[8] require(into::Module, mod::Symbol)
@ Base .\loading.jl:1144
[9] top-level scope
@ F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\backends.jl:402
[10] eval
@ .\boot.jl:368 [inlined]
[11] _initialize_backend(pkg::Plots.GRBackend)
@ Plots F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\backends.jl:401
[12] backend(pkg::Plots.GRBackend)
@ Plots F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\backends.jl:266
[13] backend(sym::Symbol)
@ Plots F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\backends.jl:276
[14] load_default_backend()
@ Plots F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\backends.jl:207
[15] backend()
@ Plots F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\backends.jl:254
[16] top-level scope
@ F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\init.jl:83
[17] include(mod::Module, _path::String)
@ Base .\Base.jl:419
[18] include(x::String)
@ Plots F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\Plots.jl:1
[19] top-level scope
@ F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\Plots.jl:176
[20] include
@ .\Base.jl:419 [inlined]
[21] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
@ Base .\loading.jl:1554
[22] top-level scope
@ stdin:1
during initialization of module GRPreferences
in expression starting at F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\init.jl:83
in expression starting at F:\Julia-1.8.2\packages\packages\Plots\tDHxD\src\Plots.jl:1
in expression starting at stdin:1
ERROR: Failed to precompile Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80] to F:\Julia-1.8.2\packages\compiled\v1.8\Plots\jl_D58.tmp.
Stacktrace:
[1] error(s::String)
@ Base .\error.jl:35
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
@ Base .\loading.jl:1707
[3] compilecache
@ .\loading.jl:1651 [inlined]
[4] _require(pkg::Base.PkgId)
@ Base .\loading.jl:1337
[5] _require_prelocked(uuidkey::Base.PkgId)
@ Base .\loading.jl:1200
[6] macro expansion
@ .\loading.jl:1180 [inlined]
[7] macro expansion
@ .\lock.jl:223 [inlined]
[8] require(into::Module, mod::Symbol)
@ Base .\loading.jl:1144
[9] eval
@ .\boot.jl:368 [inlined]
[10] eval
@ .\Base.jl:65 [inlined]
[11] repleval(m::Module, code::Expr, #unused#::String)
@ VSCodeServer c:\Users\conce\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:222
[12] (::VSCodeServer.var"#107#109"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
@ VSCodeServer c:\Users\conce\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:186
[13] with_logstate(f::Function, logstate::Any)
@ Base.CoreLogging .\logging.jl:511
[14] with_logger
@ .\logging.jl:623 [inlined]
[15] (::VSCodeServer.var"#106#108"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
@ VSCodeServer c:\Users\conce\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:187
[16] #invokelatest#2
@ .\essentials.jl:729 [inlined]
[17] invokelatest(::Any)
@ Base .\essentials.jl:726
[18] macro expansion
@ c:\Users\conce\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:34 [inlined]
[19] (::VSCodeServer.var"#61#62")()
@ VSCodeServer .\task.jl:484
GR的报错:
julia> using GR
ERROR: InitError: UndefVarError: GR_jll not defined
Stacktrace:
[1] __init__()
@ GR.GRPreferences F:\Julia-1.8.2\packages\packages\GR\mf3ag\src\preferences.jl:50
[2] _include_from_serialized(pkg::Base.PkgId, path::String, depmods::Vector{Any})
@ Base .\loading.jl:831
[3] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt64)
@ Base .\loading.jl:1039
[4] _require(pkg::Base.PkgId)
@ Base .\loading.jl:1315
[5] _require_prelocked(uuidkey::Base.PkgId)
@ Base .\loading.jl:1200
[6] macro expansion
@ .\loading.jl:1180 [inlined]
[7] macro expansion
@ .\lock.jl:223 [inlined]
[8] require(into::Module, mod::Symbol)
@ Base .\loading.jl:1144
[9] eval
@ .\boot.jl:368 [inlined]
[10] eval
@ .\Base.jl:65 [inlined]
[11] repleval(m::Module, code::Expr, #unused#::String)
@ VSCodeServer c:\Users\conce\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:222
[12] (::VSCodeServer.var"#107#109"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
@ VSCodeServer c:\Users\conce\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:186
[13] with_logstate(f::Function, logstate::Any)
@ Base.CoreLogging .\logging.jl:511
[14] with_logger
@ .\logging.jl:623 [inlined]
[15] (::VSCodeServer.var"#106#108"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
@ VSCodeServer c:\Users\conce\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:187
[16] #invokelatest#2
@ .\essentials.jl:729 [inlined]
[17] invokelatest(::Any)
@ Base .\essentials.jl:726
[18] macro expansion
@ c:\Users\conce\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:34 [inlined]
[19] (::VSCodeServer.var"#61#62")()
@ VSCodeServer .\task.jl:484
during initialization of module GRPreferences
其中,两个报错的Stacktrace [1]提到的GR.GRPreferences报错行F:\Julia-1.8.2\packages\packages\GR\mf3ag\src\preferences.jl:50是这么写的:
gr_jll_artifact_dir = GR_jll.artifact_dir
我在REPL里调用GR_jll的结果:
julia> GR_jll.artifact_dir
"F:\\Julia-1.8.2\\packages\\artifacts\\f7cfc493affccfda16b1e147bf66e7558c9f6ab0"
说明是可以调用GR_jll的,但就是无法被Plots包load。
以防万一,我也试图删掉文件夹F:\Julia-1.8.2\packages\artifacts\f7cfc493affccfda16b1e147bf66e7558c9f6ab0,然后重新Pkg.instantiate(),但是无法解决问题。
电脑Windows 10。
Julia版本为1.8:
julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf26 (2022-09-29 15:21 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 8 × Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
Threads: 1 on 8 virtual cores
Environment:
JULIA_DEPOT_PATH = F:\Julia-1.8.2\packages
JULIA_EDITOR = code
JULIA_NUM_THREADS =
请教大家,提前感谢!(问题更新时间:2023.4.13)
######下面是题主的解决方法,欢迎大家一起探讨更好的解决方法######