Problems with TikzGraphs.jl

I installed the TikzGraphs.jl package, and tried to execute the simple sample code provided

using TikzGraphs
using Graphs
g = DiGraph(4)
add_edge!(g, 1, 2)
add_edge!(g, 2, 3)
TikzGraphs.plot(g)

However I keep getting this error :

ERROR: MethodError: no method matching plot(::SimpleDiGraph{Int64})
Closest candidates are:
  plot(::Any, ::TikzGraphs.Layouts.Layout) at ~/.julia/packages/TikzGraphs/d963V/src/TikzGraphs.jl:44
  plot(::Any, ::TikzGraphs.Layouts.Layout, ::Vector{T}; args...) where T<:AbstractString at ~/.julia/packages/TikzGraphs/d963V/src/TikzGraphs.jl:44
  plot(::Any, ::Vector{T}; args...) where T<:AbstractString at ~/.julia/packages/TikzGraphs/d963V/src/TikzGraphs.jl:45
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

I would appreciate any help with fixing this issue. My Julia version is 1.8.5.

Try plotting another type of graph (not a digraph) - this might help narrow down the issue.

For some reason you are running an old version of TikzGraphs which only works with graphs from the (deprecated) LightGraphs package. This is possibly caused by adding all packages to your global environment and you have something in there which holds you back to old versions of certain packages, due to compatibility constraints.

If you use a clean environment, e.g. by doing pkg> activate --temp before adding Graphs and TikzGraphs, the example code should work.

1 Like

Thank you for the suggestion. However I tried that and it did not seem to work

(@v1.8) pkg> activate --temp
  Activating new project at `/tmp/jl_blPgHn`

julia> using TikzGraphs
[ Info: Precompiling TikzGraphs [b4f28e30-c73f-5eaf-a395-8a9db949a742]
WARNING: could not import LaTeXStrings.@L_mstr into TikzPictures

julia> using Graphs

julia> g = DiGraph(4)
{4, 0} directed simple Int64 graph

julia> add_edge!(g, 1, 2)
true

julia> add_edge!(g, 2, 3)
true

julia> TikzGraphs.plot(g)
ERROR: MethodError: no method matching plot(::SimpleDiGraph{Int64})
Closest candidates are:
  plot(::Any, ::TikzGraphs.Layouts.Layout) at ~/.julia/packages/TikzGraphs/d963V/src/TikzGraphs.jl:44
  plot(::Any, ::TikzGraphs.Layouts.Layout, ::Vector{T}; args...) where T<:AbstractString at ~/.julia/packages/TikzGraphs/d963V/src/TikzGraphs.jl:44
  plot(::Any, ::Vector{T}; args...) where T<:AbstractString at ~/.julia/packages/TikzGraphs/d963V/src/TikzGraphs.jl:45
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[7]:1

You need to do that in a new session where you haven’t already loaded some earlier version of the package and you have to add the packages to the temporary environment; otherwise they will still be loaded from your global environment.

(@v1.8) pkg> activate --temp
  Activating new project at `/tmp/jl_IMaM4M`

(jl_IMaM4M) pkg> add Graphs TikzGraphs
    Updating registry at `~/.julia/registries/General`
   Resolving package versions...
    Updating `/tmp/jl_IMaM4M/Project.toml`
⌅ [86223c79] + Graphs v1.12.1
  [b4f28e30] + TikzGraphs v1.4.0
...
1 Like

Thank you very much, this worked.
In the process I also learnt that packages can have conflicts. It seems to me that LightGraphs is the offender. To avoid having to load a temporary workspace every time and installing packages, is there any way I can remove LightGraphs ? Or do I need to re-install Julia ?

Have you tried

pkg> remove LightGraphs