GMT.jl and VSCode

I’m having some issues between GMT and VSCode. (macOS Big Sur).
Running the following in terminal works fine. I get the image in a new window.

using GMT
plot(1:10, rand(10), lw=1, lc=:blue, marker=:square,
     markeredgecolor=0, size=0.2, markerfacecolor=:red, title="Hello World",
     xlabel="Spoons", ylabel="Forks", show=true)

but running within a VSCode I get:

psconvert [ERROR]: Cannot execute Ghostscript (gs).
ERROR: LoadError: Something went wrong when calling the module. GMT error number = 79
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] gmt(::String)
   @ GMT ~/.julia/packages/GMT/jguOm/src/gmt_main.jl:295
 [3] showfig(d::Dict{Symbol, Any}, fname_ps::String, fname_ext::String, opt_T::String, K::Bool, fname::String)
   @ GMT ~/.julia/packages/GMT/jguOm/src/common_options.jl:3393
 [4] finish_PS_module(::Dict{Symbol, Any}, ::Vector{String}, ::String, ::Bool, ::Bool, ::Bool, ::Matrix{Float64}, ::Vararg{Any})
   @ GMT ~/.julia/packages/GMT/jguOm/src/common_options.jl:3549
 [5] common_plot_xyz(::String, ::Matrix{Float64}, ::String, ::Bool, ::Bool, ::Pair{Symbol, Any}, ::Vararg{Pair{Symbol, Any}})
   @ GMT ~/.julia/packages/GMT/jguOm/src/psxy.jl:221
 [6] #plot#271
   @ ~/.julia/packages/GMT/jguOm/src/plot.jl:130 [inlined]
 [7] top-level scope
   @ ~/Documents/testJulia/withgmt.jl:10
in expression starting at /Users/lalonso/Documents/testJulia/withgmt.jl:10

any pointers on how to solve this issue ? thanks.

I seems that either Ghostscript is not installed or not in the path.
Sorry, I may not be very responsive in the next few days. In case of need you can also try seek help I. The GMT forum.

Thanks… An update. Actually I was not seeing a previous error which is the following:

ERROR: LoadError: InitError: IOError: could not spawn `gmt --show-userdir`: no such file or directory (ENOENT)
Stacktrace:
  [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Any})
    @ Base ./process.jl:100
  [2] #690
    @ ./process.jl:113 [inlined]
  [3] setup_stdios(f::Base.var"#690#691"{Cmd}, stdios::Vector{Any})
    @ Base ./process.jl:197
  [4] _spawn
    @ ./process.jl:112 [inlined]
  [5] eachline(cmd::Cmd; keep::Bool)
    @ Base ./process.jl:318
  [6] eachline
    @ ./process.jl:317 [inlined]
  [7] #readlines#378
    @ ./io.jl:553 [inlined]
  [8] readlines
    @ ./io.jl:553 [inlined]
  [9] __init__(test::Bool)
    @ GMT ~/.julia/packages/GMT/jguOm/src/GMT.jl:286
 [10] __init__()
    @ GMT ~/.julia/packages/GMT/jguOm/src/GMT.jl:266
 [11] _include_from_serialized(path::String, depmods::Vector{Any})
    @ Base ./loading.jl:768
 [12] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String)
    @ Base ./loading.jl:854
 [13] _require(pkg::Base.PkgId)
    @ Base ./loading.jl:1097
 [14] require(uuidkey::Base.PkgId)
    @ Base ./loading.jl:1013
 [15] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:997
 [16] eval
    @ ./boot.jl:373 [inlined]
 [17] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1196
 [18] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./essentials.jl:716
 [19] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base ./essentials.jl:714
 [20] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/eval.jl:211
 [21] (::VSCodeServer.var"#60#64"{Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/eval.jl:155
 [22] withpath(f::VSCodeServer.var"#60#64"{Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/repl.jl:185
 [23] (::VSCodeServer.var"#59#63"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/eval.jl:153
 [24] hideprompt(f::VSCodeServer.var"#59#63"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/repl.jl:36
 [25] (::VSCodeServer.var"#58#62"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/eval.jl:124
 [26] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:511
 [27] with_logger
    @ ./logging.jl:623 [inlined]
 [28] (::VSCodeServer.var"#57#61"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/eval.jl:201
 [29] #invokelatest#2
    @ ./essentials.jl:716 [inlined]
 [30] invokelatest(::Any)
    @ Base ./essentials.jl:714
 [31] macro expansion
    @ ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
 [32] (::VSCodeServer.var"#55#56")()
    @ VSCodeServer ./task.jl:423
during initialization of module GMT

and if I do in my terminal which gmt I get:

/usr/local/bin/gmt

as I said plotting in the Julia repl works just fine.

Is the Julia: Use Plot Pane parameter in your VS code checked or not?

Does it run from a normal REPL?
One thing that is known to not work is the GMT Bundle distributed in the GMT site. The lib paths are screwed when seen from within Julia and the dependencies are not found.
On the other hand the CI tests are run from a Mac VM (that builds GMT from brew). But if you don’t have a previous installation it should have been installed by Conda. Was not that the case?

I have the same issue and error message running GMT in VSCode but only for GMT plotting commands inside .jl files. Interactively running GMT commands in an .ipynb cell works fine.