# Could not load library librsvg - very strange error

**URL:** <https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276>\
**Category:** General Usage\
**Created:** [February 27, 2019, 7:47pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276 "2019-02-27T19:47:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [February 27, 2019, 7:47pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/1 "2019-02-27T19:47:16Z")

</div>

I’m using VegaLite library, and after some update it does not load when imported after `PyPlot`:

```julia
using PyPlot
using VegaLite

```

gives the following:

```julia
ERROR: InitError: error compiling __init__ : could not load library "/usr/lib/x86_64-linux-gnu/librsvg-2.so.2"
/lib/x86_64-linux-gnu/libgio-2.0.so.0: undefined symbol: g_spawn_async_with_fds
Stacktrace:
 [1] _include_from_serialized(::String, ::Array{Any,1}) at ./loading.jl:633
 [2] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:713
 [3] _tryrequire_from_serialized(::Base.PkgId, ::UInt64, ::String) at ./loading.jl:648
 [4] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:702
 [5] _require(::Base.PkgId) at ./loading.jl:937
 [6] require(::Base.PkgId) at ./loading.jl:858
 [7] require(::Module, ::Symbol) at ./loading.jl:853
during initialization of module Rsvg

```

Following to Rsvg.jl ` __init__ ` method I narrowed this error down to this code:

```julia
julia -E 'using PyPlot; ccall((:rsvg_set_default_dpi, "librsvg-2.so.2"), Nothing, (Float64,), 1.)'

```

gives the same error, and executes fine if I remove `using PyPlot`. The issue seems related to some interaction with python and plots, as the following line (for example) also gives the same error:

```julia
julia -E 'using PyCall; pyimport("seaborn"); ccall((:rsvg_set_default_dpi, "librsvg-2.so.2"), Nothing, (Float64,), 1.)'

```

At the same time,

```julia
julia -E 'ccall((:rsvg_set_default_dpi, "librsvg-2.so.2"), Nothing, (Float64,), 1.)'

```

correctly prints `nothing` without errors.

Any idea how to debug and fix this?

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [February 27, 2019, 11:17pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/2 "2019-02-27T23:17:01Z")

</div>

I’m not an expert on this, but here is my suspicion: PyPlot.jl somehow loads a system `librsvg`, and then when Rsvg.jl later tries to load its own copy of `librsvg` things go wrong: because a `librsvg` is already loaded, Rsvg.jl won’t get the version of `librsvg` that it downloaded via its build.jl script, but instead it gets the system version of the library that was loaded by PyPlot.jl, and that is somehow a different version that is incompatible. Or I might be on a completely wrong track here 🙂

I’m going to ping some folks that either might be able to understand this better than I do, or are associated with packages that play a role here: @lobingera, @stevengj, @staticfloat.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [February 27, 2019, 11:18pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/3 "2019-02-27T23:18:25Z")

</div>

Oh, and just for good measure I’ll repeat my general plea: it would be fantastic if someone would port the Gtk.jl/Cairo.jl/Rsvg.jl stack over to BinaryBuilder.jl. I don’t even know whether that would help here, but hey, I might as well mention this again 😉

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [February 28, 2019, 5:21pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/4 "2019-02-28T17:21:31Z")

</div>

I think David is partially right, a certain .so has been loaded and in the process of opening librsvg this has a mismatch. My candiate of choice would be libgio which has been recently added to Rsvg.jl for handling of huge svgs.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [February 28, 2019, 6:32pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/5 "2019-02-28T18:32:31Z")

</div>

@staticfloat is there a plan for situations like this? What can we do to fix this?

---

<div class="post-metadata">

**Author:** ![staticfloat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/staticfloat/32/34_2.png) [@staticfloat](https://discourse.julialang.org/u/staticfloat)\
**Post date:** [February 28, 2019, 8:58pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/6 "2019-02-28T20:58:01Z")

</div>

In the short term, try explicitly `dlopen()`'ing the `libgio` you want to use before running `using PyPlot`.

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [March 1, 2019, 6:28am UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/7 "2019-03-01T06:28:10Z")

</div>

This workaround isn’t even needed in my case - I just do `using VegaLite` first, and `using PyPlot` after that. The question is about this situation in general, because it looks quite strange and difficult to debug - think if there were more than two libraries involved.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [April 2, 2019, 12:49am UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/8 "2019-04-02T00:49:00Z")

</div>

@staticfloat, just out of curiosity, is there a long term plan to address this?

---

<div class="post-metadata">

**Author:** ![staticfloat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/staticfloat/32/34_2.png) [@staticfloat](https://discourse.julialang.org/u/staticfloat)\
**Post date:** [April 8, 2019, 5:27pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/9 "2019-04-08T17:27:25Z")

</div>

Yes, the long-term plan is [Pkg + BinaryProvider · Issue #841 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/841)

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [April 8, 2019, 5:43pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/10 "2019-04-08T17:43:23Z")

</div>

@staticfloat how would the problem discussed here in this thread be addressed by [Pkg + BinaryProvider · Issue #841 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/841)? The problem here in this thread seems to be that something that is _not_ under BinaryProvider control loads a version of shared library `libA`, and then a package that uses BinaryProvider.jl that also needs `libA` never gets the version that it requires, but instead the version that the non-BinaryProvider package loaded. Would that specifically be resolved with that new proposal? I didn’t really see anything in that thread that addressed this specific situation.

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [April 8, 2019, 5:45pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/11 "2019-04-08T17:45:24Z")

</div>

Does BB support cargo + rust?

---

<div class="post-metadata">

**Author:** ![staticfloat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/staticfloat/32/34_2.png) [@staticfloat](https://discourse.julialang.org/u/staticfloat)\
**Post date:** [April 8, 2019, 7:10pm UTC](https://discourse.julialang.org/t/could-not-load-library-librsvg-very-strange-error/21276/12 "2019-04-08T19:10:46Z")

</div>

> I didn’t really see anything in that thread that addressed this specific situation.

Sorry, I think I got two wires crossed in my head; you’re right, that is tangentially related at best (it is related to ensuring that dependent packages can load their dependencies properly) but doesn’t address the core issue here.

This is not a julia-specific problem, and is very complex due to the interaction of Python, whose behavior we cannot regulate as closely as that of Julia packages. The fundamental issue is that we are loading two different library versions, but our typical efforts to control which versions get loaded (the link I placed above) won’t work here, because Python can do whatever it wants; it knows nothing about Pkg or BinaryProvider, etc…

The OS, in general, will try to steer you clear of loading multiple copies of the same dynamic library into your address space (e.g. if you try to load something called `libgio` and it’s already loaded, it will just return immediately; but if you say “load `/path/to/libgio.2.3.1.so`”, it will actually try to load that library) so depending on how python and julia try to load these libraries (and which versions of the libraries are available on your system) you can get very different behavior by re-ordering your statements.

The best advice I can give is to try and load everything from Julia side first; beyond that I’m not sure what we can do, because importing python into Julia’s address space and allowing it to load libraries means that it can really do whatever it wants, and we can’t really control it.
