haskellinstallationcabalhaskell-diagrams

How to install diagrams?


I am trying to install the diagrams package. If I do

cabal install diagrams

I get (towards the end)

Configuring lens-4.2...
Building lens-4.2...
Preprocessing library lens-4.2...

src/Control/Lens/Internal/Zoom.hs:47:8:
    Could not find module `Control.Monad.Trans.Except'
    It is a member of the hidden package `transformers-0.4.1.0'.
    Perhaps you need to add `transformers' to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.
Failed to install lens-4.2
cabal: Error: some packages failed to install:
diagrams-1.2 depends on lens-4.2 which failed to install.
diagrams-contrib-1.1.2 depends on lens-4.2 which failed to install.
diagrams-core-1.2.0.1 depends on lens-4.2 which failed to install.
diagrams-lib-1.2.0.1 depends on lens-4.2 which failed to install.
diagrams-svg-1.1 depends on lens-4.2 which failed to install.
force-layout-0.3.0.4 depends on lens-4.2 which failed to install.
lens-4.2 failed during the building phase. The exception was:
ExitFailure 1

So then I try

$cabal install lens transformers diagrams

And I get (towards the end)

In-place registering diagrams-lib-1.2.0.1...
Installing library in /home/theking/.cabal/lib/diagrams-lib-1.2.0.1/ghc-7.6.3
Registering diagrams-lib-1.2.0.1...
Installed diagrams-lib-1.2.0.1
cabal: Error: some packages failed to install:
cairo-0.12.5.3 failed during the configure step. The exception was:
ExitFailure 1
diagrams-0.3 depends on glib-0.12.5.4 which failed to install.
diagrams-cairo-1.2 depends on glib-0.12.5.4 which failed to install.
glib-0.12.5.4 failed during the configure step. The exception was:
ExitFailure 1
pango-0.12.5.3 depends on glib-0.12.5.4 which failed to install.

So I tried one more thing

$ cabal install glib
Resolving dependencies...
[1 of 2] Compiling SetupWrapper     ( /tmp/glib-0.12.5.4-9179/glib-0.12.5.4/SetupWrapper.hs, /tmp/glib-0.12.5.4-9179/glib-0.12.5.4/dist/setup/SetupWrapper.o )
[2 of 2] Compiling Main             ( /tmp/glib-0.12.5.4-9179/glib-0.12.5.4/Setup.hs, /tmp/glib-0.12.5.4-9179/glib-0.12.5.4/dist/setup/Main.o )
Linking /tmp/glib-0.12.5.4-9179/glib-0.12.5.4/dist/setup/setup ...
[1 of 2] Compiling Gtk2HsSetup      ( Gtk2HsSetup.hs, dist/setup-wrapper/Gtk2HsSetup.o )
[2 of 2] Compiling Main             ( SetupMain.hs, dist/setup-wrapper/Main.o )
Linking dist/setup-wrapper/setup ...
Configuring glib-0.12.5.4...
setup: The program gtk2hsC2hs version >=0.13.8 is required but the version
found at /usr/bin/gtk2hsC2hs is version 0.13.6
Failed to install glib-0.12.5.4
cabal: Error: some packages failed to install:
glib-0.12.5.4 failed during the configure step. The exception was:
ExitFailure 1

And I got stuck here. So how do I install diagrams. I don't really care how it gets installed (getting a little fed up with cabal) as long as it gets installed.

The awesome stuff this package does

Notes: I am on linux. I also tried cabal install gtk2hs-buildtools.


Solution

  • The second error block says that:

    diagrams-0.3 depends on glib-0.12.5.4 which failed to install.
    

    diagrams-0.3 is a very old version of diagrams, and in normal circumstances cabal shouldn't be trying to install it. Recent versions of diagrams do not even depend on diagrams-cairo, so as long as you don't need the Cairo backend you can work around the Cairo/GTK issues by asking for the current version of diagrams, as in:

    cabal install diagrams-1.2
    

    Ideally, it would be good to find out why your cabal is pulling the old version. cabal install diagrams --dry-run (which only show the packages that would be pulled without actually installing them) and ghc-pkg list (which shows the packages currently in your system) might help figuring that out.

    As for the Cairo-related issues, as Daniel Wagner suggests a PATH issue might be preventing cabal from using the latest versions of the gtk2hs-buildtools you have installed. For instance, you might have a global installation of the tools, which is overriding the local one you have done with cabal. ghc-pkg list allows you to verify that. Also, check this relevant question.