Im trying to run the ghci REPL but this happens
# ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
ghc: can't find a package database at /usr/lib/ghc/package.conf.d
when trying to list installed modules:
# ghc-pkg list
ghc-pkg: /var/lib/ghc/package.conf.d: openFile: does not exist (No such file or directory)
when trying to install openFile:
# cabal install openFile
cabal: ghc-pkg: /var/lib/ghc/package.conf.d: openFile: does not exist (No such
file or directory)
Related
I'm on macOS running stack/GHCi version 8.4.3:
import Test.QuickCheck fails at both the GHCi prompt and in my .hs files. Either way I'm told it's not found.
GHCi Prelude>
<no location info>: error:
Could not find module ‘Test.QuickCheck’
It is not a module in the current program, or in any known package.
in .hs file >
"Could not find module ‘Test.QuickCheck’ '
The source code is on this page but I'm not sure how to install a new package into stack manually. From my brief reading when I googled "install Haskell package" it suggests installing a cabal package universally is a bad idea. Not sure this is a cabal package, and in any case it would be good to be able to import it for any project I think in my case.
The modern way to do this for a quick ghci session is to use cabal repl and add a dependency on QuickCheck:
% cabal repl --build-depends QuickCheck
> import Test.QuickCheck
Test.QuickCheck> -- ^_^
For longer-term programming (i.e. not just quick tests of stuff in ghci), the modern way is to create a cabal package and add QuickCheck to the build-depends section in the *.cabal produced:
% mkdir fancy-package
% cd fancy-package
% cabal init
<follow prompts>
% $EDITOR fancy-package.cabal
<find build-depends: and add, for example, QuickCheck ^>= 2.14 to the list>
% cabal repl
*Main> import Test.QuickCheck
*Main Test.QuickCheck> -- ^_^
I am getting the following error.
(base) Pauls-MBP-2:~ reiners$ ghci
GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help
Prelude> import Euterpea
<no location info>: error:
Could not find module ‘Euterpea’
It is not a module in the current program, or in any known package.
Prelude>
I had previously installed Euterpea with the command
cabal install Euterpea
In fact, the import actually worked. However, for other reasons, I closed that command prompt, and now it's not working.
I also tried running it from the cabal repl and got the same result:
(base) Pauls-MBP-2:~ reiners$ cabal repl
Resolving dependencies...
Build profile: -w ghc-8.8.4 -O1
In order, the following will be built (use -v for more details):
- fake-package-0 (lib) (first run)
Configuring library for fake-package-0..
Preprocessing library for fake-package-0..
Warning: No exposed modules
GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /var/folders/8k/74p15mf15zsg82l4r7xz28t00000gn/T/cabal-repl.-19576/setcwd.ghci
Prelude> import Euterpia
<no location info>: error:
Could not find module ‘Euterpia’
It is not a module in the current program, or in any known package.
Prelude>
I'm using macOS Catalina (10.15.7).
Here are my version info:
cabal-install version 1.24.0.2
compiled using version 1.24.2.0 of the Cabal library
On Ubuntu 18.04
$ ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Prelude> import Control.Monad.Par
<no location info>: error:
Could not find module ‘Control.Monad.Par’
Perhaps you meant
Control.Monad.Fail (from base-4.9.1.0)
Control.Monad.Fix (from base-4.9.1.0)
Control.Monad.RWS (needs flag -package-key mtl-2.2.1#mtl-2.2.1-BLKBelFsPB3BoFeSWSOYj6)
Would appreciate any help on how to get Control.Monad.Par to work.
In general, Could not find module ‘...’ means you don't have the package installed1. You can search the module name on hayoo to get the package name, and then do:
cabal install [package name]
Or if you're using Stack for your project (recommended), you can add the package name to the build-depends section in your *.cabal file.
1It could also mean you misspelled the module name, the package was installed incorrectly, GHC isn't looking for the package in the place it was installed, or some other weird thing is going on, but I won't go into that.
I'm trying to use Posgres and a cabal sandbox for a new project. I've got postgresql-simple installed, as evidenced by installation outputs:
$ cabal install postgresql-simple
Resolving dependencies...
All the requested packages are already installed:
postgresql-simple-0.4.10.0
Use --reinstall if you want to reinstall anyway.
Notice: installing into a sandbox located at
/Users/inaimathi/projects/hs-test/.cabal-sandbox
but when I try to import the library in ghci, I get the error
ghci
GHCi, version 7.10.1: http://www.haskell.org/ghc/ :? for help
Prelude> import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple
<no location info>:
Could not find module ‘Database.PostgreSQL.Simple’
It is not a module in the current program, or in any known package.
Prelude>
Can anyone point out what I'm doing wrong?
You need to start GHCi with a -package-db=... flag pointing to /Users/inaimathi/projects/hs-test/.cabal-sandbox
so
ghci -package-db=/Users/inaimathi/projects/hs-test/.cabal-sandbox
or thereabouts...
I encounter a strange situation in GHCI, don't know if anyone observed similar case. For some module, when I have it in the search path both by -package-conf, and also by -i, GHCI fails when I try to import the module with 'module is not loaded: FooModule'.
:module loads it fine however
or I can do :load FooModule, :m to clear the import list, and then import FooModule
or I can remove the path from -i and then it imports fine
Tracked this to be the otherwise -> modNotLoadedError m loc case in GHC, where otherwise ~ modulePackageId = this_pkg (the meaning of which I don't know).
This is not entirely systematic, there are some module which are both in package and source path, but can be imported.
GHC only knows about packages that are installed. To see which packages are installed, use the ghc-pkg list command:
$ ghc-pkg list
/usr/lib/ghc-6.12.1/package.conf.d:
Cabal-1.7.4
array-0.2.0.1
base-3.0.3.0
base-4.2.0.0
bin-package-db-0.0.0.0
binary-0.5.0.1
bytestring-0.9.1.4
containers-0.2.0.1
directory-1.0.0.2
(dph-base-0.4.0)
(dph-par-0.4.0)
(dph-prim-interface-0.4.0)
(dph-prim-par-0.4.0)
(dph-prim-seq-0.4.0)
(dph-seq-0.4.0)
extensible-exceptions-0.1.1.0
ffi-1.0
filepath-1.1.0.1
(ghc-6.12.1)
ghc-prim-0.1.0.0
haskeline-0.6.2
haskell98-1.0.1.0
hpc-0.5.0.2
integer-gmp-0.1.0.0
mtl-1.1.0.2
old-locale-1.0.0.1
old-time-1.0.0.1
pretty-1.0.1.0
process-1.0.1.1
random-1.0.0.1
rts-1.0
syb-0.1.0.0
template-haskell-2.4.0.0
terminfo-0.3.1
time-1.1.4
unix-2.3.1.0
utf8-string-0.3.4