Haskell package installed but not found

2020-03-23 18:03发布

I installed diagrams, and it seems to be there, but GHCi doesn’t find it. I tried adding the local sandbox to the command line (-package-db), but still no luck. Any suggestions?

   C:\Users\guthrie>
   C:\Users\guthrie>cabal install diagrams
    Resolving dependencies...
    All the requested packages are already installed:
   diagrams-1.2
   Use --reinstall if you want to reinstall anyway.

I find it in:

  C:\Users\guthrie\.cabal-sandbox\i386-windows-ghc-7.6.3-packages.conf.d
        (diagrams-1.2, diagrams-contrib, -core, -lib, -svg) 

But running: “cabal repl” or using the GHC(i) flag “-package-db=…” fail to find it:

C:\Users\guthrie>cabal repl
GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :m + Diagrams.Prelude

<no location info>:
    Could not find module `Diagrams.Prelude'
   It is not a module in the current program, or in any known package.
Prelude>

To clarify; ignoring the cabal invocations, using GHC/i directly, and the program diagramsDemo.hs:

--  http://projects.haskell.org/diagrams/doc/quickstart.html
--
import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine

main = mainWith (circle 1 :: Diagram B R2)

Gives:

C:\Users\guthrie\Desktop\xFer\Graphics>ghc --make diagramsDemo.hs

diagramsDemo.hs:7:8:
    Could not find module `Diagrams.Backend.SVG.CmdLine'
    Use -v to see a list of the files searched for.

C:\Users\guthrie\Desktop\xFer\Graphics>ghc --make diagramsDemo.hs -package-db=C:\Users\guthrie\.cabal-sandbox\i386-windows-ghc-7.6.3-packages.conf.d

diagramsDemo.hs:7:8:
    Could not find module `Diagrams.Backend.SVG.CmdLine'
    Use -v to see a list of the files searched for.

1条回答
Deceive 欺骗
2楼-- · 2020-03-23 18:58

As bheklilr said, if ghci is started with cabal repl, it will only find packages specified as a dependency in the .cabal file.

However you can start it with cabal exec ghci, then it will find all packages installed in the sandbox.

The same is true for invoking ghc (cabal build vs. cabal exec ghc), but note that if you want to pass flags you have to use --, like in cabal exec ghc -- -O2 Main.hs. Alternatively you can use cabal exec bash and launch ghci or ghc in the new shell.

cabal exec was added with Cabal 1.20.

查看更多
登录 后发表回答