Errors associated with "using GMT"

I just installed the mapping package to my Julia and I can verify that my GMT package was installed:

Pkg.status("GMT")
      Status `~/.julia/environments/v1.6/Project.toml`
  [5752ebe1] GMT v0.37.1

However, a simple “using GMT” script will give me the below error, preventing me from using the package.

┌ Info: Precompiling GMT [5752ebe1-31b9-557e-87aa-f909b540aa54]
└ @ Base loading.jl:1342
Base.IOError("could not spawn `gmt --version`: no such file or directory (ENOENT)", -2)
    Building Conda → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/299304989a5e6473d985212c28928899c74e9421/build.log`
    Building GMT ──→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/258a0ed178a8a08544e92edf0408885423bd6d16/build.log`

It looks like Julia can’t find GMT. Is it on your path ?

1 Like

I installed it using the below command:

using Pkg
Pkg.add("GMT")

I assume it will be installed in a location that Julia can find?

What you have installed is the GMT.jl package. It’s a Julia wrapper for the GMT tools. You need to install them also

1 Like

According to the README, it should now install its own GMT library, although the recommended way is for you to install it in your system before adding the package (https://github.com/GenericMappingTools/GMT.jl).

You could try:

Pkg.rm("GMT")
ENV["FORCE_INSTALL_GMT"] = true
Pkg.add("GMT")

And see if it triggers the install.
Pinging @joa-quim.

1 Like

Right, ] add GMT should trigger the awfully wasteful install via conda (that’s one of the reasons why it is advised to install the GMT package beforehand to avoid this). And things should work. They do normally and I don’t understand why it failed for you.

One other way of forcing the GMT installation is by running GMT.force_precompile()

1 Like

Many thanks, All.

I just removed GMT and am now re-installing it by following the Homebrew approach. It seems to be going well:
https://github.com/GenericMappingTools/gmt/blob/master/INSTALL.md#install-via-homebrew

So I followed all the below steps:


Installation of GMT through [Homebrew](https://brew.sh/) is extremely simple. Installing Homebrew itself is a one line command only (see [the Homebrew page](https://brew.sh/)). You may need to update the formulas so for that you will do:

brew update && brew upgrade


For the latest stable GMT 6 release, use:

brew install gmt


For the latest unstable/developing version (i.e. the master branch), run:

brew install gmt --HEAD


You also need to install other GMT run-time dependencies separately:

brew install ghostscript graphicsmagick ffmpeg

but GMT does not even show up in my Pkg.status(“GMT”). So I run Pkg.add(“GMT”) again. Now I have the below error message when using the GMT package:

ERROR: LoadError: InitError: could not load library “/Users/xxx/.julia/conda/3/lib/libgdal.29.dylib”

dlopen(/Users/xxx/.julia/conda/3/lib/libgdal.29.dylib, 1): Library not loaded: @rpath/libhdf5.200.dylib

Referenced from: /Users/xxx/.julia/conda/3/lib/libgdal.29.dylib

Reason: Incompatible library version: libgdal.29.dylib requires version 202.0.0 or later, but libhdf5.200.dylib provides version 201.0.0

Stacktrace:

[1] GDALVersionInfo( a1::String )

@ GMT.Gdal ~/.julia/packages/GMT/TPV4a/src/gdal.jl:317

[2] init()

@ GMT.Gdal ~/.julia/packages/GMT/TPV4a/src/gdal.jl:2403

[3] _include_from_serialized( path::String, depmods::Vector{Any} )

@ Base ./loading.jl:696

[4] _require_search_from_serialized( pkg::Base.PkgId, sourcepath::String )

@ Base ./loading.jl:782

[5] _require( pkg::Base.PkgId )

@ Base ./loading.jl:1020

[6] require( uuidkey::Base.PkgId )

@ Base ./loading.jl:936

[7] require( into::Module, mod::Symbol )

@ Base ./loading.jl:923

during initialization of module Gdal

Hmmm, now you seem to be having a conflict between the Homebrew and Conda installations. So, it turns out that your first did install GMT from Conda but for some reason it errored.

I don’t know how to remove the Conda installation cleanly (maybe import conda; conda.rm("gmt") or some variation of this).

Try what I mentioned above. Run
GMT.force_precompile()
and restart.

Try also in MacOS terminal window to run gmt --version to check that your Homebrew installation is working fine. GMT.jl should be able to pick this install and work as expected.

1 Like

Many thanks!

Here is the error when running import conda

**ERROR:** ArgumentError: Package conda not found in current path:

- Run `import Pkg; Pkg.add("conda")` to install the conda package.

Stacktrace:

[1] **require(** into::Module, mod::Symbol **)**

@ Base ./loading.jl:893

and this?

I’m able to run GMT.force_precompile() without any issues. I’m also able to run using GMT without any errors now.

However, import conda still gives me the below error, even after I restarted my computer:

ERROR: ArgumentError: Package conda not found in current path:

  • Run import Pkg; Pkg.add("conda") to install the conda package.

Stacktrace:

[1] require( into::Module, mod::Symbol )

@ Base ./loading.jl:893

The import conda was to get rid of the GMT Conda installation cleanly. Otherwise I’m afraid you have to remove it manually and brute force. But otherwise if using GMT work you are ready to go.

Unfortunately, the using GMT command only works if I run it within the Julia application:


   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.3 (2021-09-23)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |
**julia>** using GMT

It does not work if it is written in a sample.jl file and I run it in a terminal as julia sample.jl

It seems that reason is that the library version is too old?
Incompatible library version: libgdal.29.dylib requires version 202.0.0 or later, but libhdf5.200.dylib provides version 201.0.0

BTW, I’m using Mac OS Big Sur Version 11.6. Could this be the problem?

You mean that it works if you run it from the Julia REPL as

include("sample.jl")

but not from terminal as?

julia sample.jl

The error messages seem to indicate the usual unix mess with dependencies conflicts. In this case between the HDF and the netCDF libraries. Being true this means that Homebrew screwed when it built GMT and its dependencies. You built the GMT dev version instead of the stable 6.2.0 release (latest). Should be no problem with this but who knows.

1 Like

Thanks for the help!

When I run it from the REPL, I just typed “using GMT”. I did not use include(“sample.jl”). That worked.

Is there an instruction page so that I can uninstall everything and reinstall them all over again?

Not sure what you mean by everything. Sure you can remove GMT.jl and reinstall (] rm GMT; add GMT) but don’t believe this will make any difference. Regarding Homebrew I don’t remember (you can google it) but should be arround brew uninstall gmt, netcdf. The problem here seems to be the netCDF library. But then how to explain that it works from within the Julia REPL. I’m confused with this.

1 Like

I am not on a MacOS, never used GMT, however, how about starting from scratch in a brand new Julia environment and using Conda that comes with PythonCall.jl. This is not about “uninstall everything and reinstall them all over again”, however, it should bring pretty similar results (I have not tried it):

# Creating a new project directory
    mkdir path/GMTenv # make a directory for your project environment 
# Start Julia
    julia
# Activating a new Julia environment;
    using Pkg
    cd("path/GMTenv") # cd to your project environment
    pwd() # double check if you are in the right directory
    Pkg.activate(".") # activate a new environment
    Pkg.instantiate()
    Pkg.status() # double check if its activated
# Adding and using PythonCall.jl;
    Pkg.add(url="https://github.com/cjdoris/PythonCall.jl.git") # adding master version of PythonCall 
    using PythonCall
# Checks    
    PythonCall.Deps.status() # check
    PythonCall.Deps.conda_env() # check
    PythonCall.Deps.user_deps_file() # check
# Installing GMT from conda channel;
    PythonCall.Deps.add(conda_channels = ["conda-forge"]) # add conda-forge chennel ## COMMENT OUT WHEN RUNNING julia sample.jl
    PythonCall.Deps.add(conda_packages = ["gmt=6.2"]) # add gmt 6.2. 
    # If by any chance you need additional dependencies like netcdf install them in a similar way
# Checks
    PythonCall.Deps.status() # check
    PythonCall.Deps.conda_env() # check
    PythonCall.Deps.user_deps_file() # check
# Exit julia (IT WILL BE NEEDED AFTER ADDING CONDA PACKAGES)
    exit()
# And start julia again (IT WILL BE NEEDED AFTER ADDING CONDA PACKAGES)
    julia
# Activating a Julia environment;
    using Pkg
    cd("path/GMTenv") # cd to your project environment
    pwd() # double check if you are in the right directory
    Pkg.activate(".") # activate a new environment
    Pkg.instantiate()
    Pkg.status() # double check if its activated
# By using PythonCall, your new Conda environment will be activated in your Julia project environment
    using PythonCall
# Checks    
    PythonCall.Deps.status() # check
    PythonCall.Deps.conda_env() # check
    PythonCall.Deps.user_deps_file() # check 
# Add GMT.jl
    Pkg.add(GMT) ## COMMENT OUT WHEN RUNNING julia sample.jl
    using GMT
# Your sample project code goes here:
1 Like

Many thanks for the recommended fixes. I have run all the codes except these very last two steps:

# Add GMT.jl
    Pkg.add(GMT) ## COMMENT OUT WHEN RUNNING julia sample.jl
    using GMT

It throws out an error saying UndefVarError: GMT not defined. Should I change it to Pkg.add("GMT")?

After this, when I use GMT, my sample.jl does not necessarily need to be in the path/GMTenv directory am I right? All I need to do is to put “using GMT” in my sample.jl?

Thanks.

Absolutely. Typo.