无法通过 cabal 安装“System.Random”

2 haskell cabal cabal-install

我尝试通过 Powershell 和 Git Bash 通过 cabal 安装“System.Random”。

得到这个结果。

PS C:\Users\xxx> cabal install random
Resolving dependencies...
Up to date
Warning: You asked to install executables, but there are no executables in
target: random. Perhaps you want to use --lib to install libraries instead.
Run Code Online (Sandbox Code Playgroud)

然后我尝试像这样输入

cabal install --lib random
Resolving dependencies...

and 

cabal install random --lib
Run Code Online (Sandbox Code Playgroud)

两个输出 解决依赖关系... 最新没有警告。但 ghci 找不到模块“System.Random”

输入 cabal install random 仍然有相同的结果和警告。

HTN*_*TNW 5

全局安装软件包是一个坏主意,所以cabal install不要这样做。该包已构建并放入 Cabal 包数据库中,但 GHC 不会找到它,除非您明确告诉 Cabal 将 GHC 指向它:

cabal repl -b random # -b is short for --build-depends
# Note that cabal install isn't really necessary: the above command would have installed random if it wasn't there already
Run Code Online (Sandbox Code Playgroud)

但是,我认为您的 Cabal/GHC 安装可能已经过时。当你这样做时cabal install --lib random,最新版本的 Cabal 应该在 写出一个“环境文件” %APPDATA%\ghc\arch-os-ghcversion\environments\default,然后 GHC 应该自动读取(GHCi 应该说类似Loaded package environment from ...),然后它应该找到已安装的包。如果您使用的是最新版本的一切,

cabal install --lib random
ghci
Run Code Online (Sandbox Code Playgroud)

应该工作。