# Errors associated with "using GMT"

**URL:** https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393
**Category:** Performance
**Tags:** question, gmt
**Created:** [October 26, 2021, 9:42am UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393 "2021-10-26T09:42:27Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 26, 2021, 9:42am UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/1 "2021-10-26T09:42:27Z")

</div>

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

```julia
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.

```julia
┌ 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`

```

---

<div class="post-metadata">

### Author: ![junelac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/junelac/32/29728_2.png) [@junelac](https://discourse.julialang.org/u/junelac)
#### Post date: [October 26, 2021, 10:43am UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/2 "2021-10-26T10:43:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 26, 2021, 1:04pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/3 "2021-10-26T13:04:11Z")

</div>

I installed it using the below command:

```julia
using Pkg
Pkg.add("GMT")

```

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

---

<div class="post-metadata">

### Author: ![junelac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/junelac/32/29728_2.png) [@junelac](https://discourse.julialang.org/u/junelac)
#### Post date: [October 26, 2021, 5:13pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/4 "2021-10-26T17:13:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)
#### Post date: [October 26, 2021, 5:37pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/5 "2021-10-26T17:37:39Z")

</div>

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](https://github.com/GenericMappingTools/GMT.jl)).

You could try:

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

```

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

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [October 26, 2021, 6:04pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/6 "2021-10-26T18:04:01Z")

</div>

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()`

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 26, 2021, 6:11pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/7 "2021-10-26T18:11:53Z")

</div>

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](https://github.com/GenericMappingTools/gmt/blob/master/INSTALL.md#install-via-homebrew)

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 26, 2021, 6:27pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/8 "2021-10-26T18:27:30Z")

</div>

So I followed all the below steps:

```julia

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

```julia

For the latest stable GMT 6 release, use:

```

brew install gmt

```julia

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

```

brew install gmt --HEAD

```julia

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

```

brew install ghostscript graphicsmagick ffmpeg

```julia

```

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

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [October 26, 2021, 7:02pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/9 "2021-10-26T19:02:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 26, 2021, 7:07pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/10 "2021-10-26T19:07:07Z")

</div>

Many thanks!

Here is the error when running `import conda`

```julia
**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

```

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [October 26, 2021, 7:12pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/11 "2021-10-26T19:12:39Z")

</div>

> [@joa-quim](#):
>
> `GMT.force_precompile()`  
> and restart.

and this?

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 26, 2021, 7:20pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/12 "2021-10-26T19:20:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [October 26, 2021, 7:40pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/13 "2021-10-26T19:40:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 26, 2021, 10:26pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/14 "2021-10-26T22:26:26Z")

</div>

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

```julia

   _ _ _(_)_ | 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?

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [October 26, 2021, 11:01pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/15 "2021-10-26T23:01:48Z")

</div>

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

```julia
include("sample.jl")

```

but not from terminal as?

```julia
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.

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 26, 2021, 11:08pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/16 "2021-10-26T23:08:21Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [October 26, 2021, 11:15pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/17 "2021-10-26T23:15:57Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)
#### Post date: [October 26, 2021, 11:21pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/18 "2021-10-26T23:21:34Z")

</div>

> [@leon](#):
>
> Is there an instruction page so that I can uninstall everything and reinstall them all over again?

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):

```julia
# 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()

```

```julia
# 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:

```

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 26, 2021, 11:45pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/19 "2021-10-26T23:45:36Z")

</div>

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

```julia
# 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.

---

<div class="post-metadata">

### Author: ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)
#### Post date: [October 26, 2021, 11:48pm UTC](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393/20 "2021-10-26T23:48:35Z")

</div>

> [@leon](#):
>
> It throws out an error saying `UndefVarError: GMT not defined` . Should I change it to `Pkg.add("GMT")` ?

Absolutely. Typo.

[Next page](https://discourse.julialang.org/t/errors-associated-with-using-gmt/70393.md?page=2)
