未来遇到此类问题的人请注意:
复制下面任何一个命令都是不明智的,请不要执行它们。只需查看Zeta的答案,了解为什么我错误地处理了这个问题。
原始问题
我的沙盒似乎被一些全局版本的软件包卡住了,而不是使用沙盒版本。我在SO上寻找答案,许多问题都没有具体的解决方法,或者略有不同,所以我无法让我的设置运行起来。这是我的情况:
1. Version of cabal is old:
$ cabal --v
cabal-install version 1.16.0.2
using version 1.16.0 of the Cabal library
哦,糟糕,这是旧版本的代码,无法在沙盒中运行。
2. Install cabal with cabal
$ cabal install cabal
Resolving dependencies...
Downloading Cabal-1.22.6.0...
...lots of stuf...
Registering Cabal-1.22.6.0...
Installed Cabal-1.22.6.0
看起来不错。
3. Try it out:
$ cabal sandbox init
cabal: unrecognised command: sandbox (try --help)
嗯。
$ which cabal
/usr/bin/cabal
啊。
$ ${HOME}/.cabal/bin/cabal --version
cabal-install version 1.22.2.0
using version 1.22.2.0 of the Cabal library
啊哈。
$ export PATH="${HOME}/.cabal/bin/:$PATH"
$ export PATH="${HOME}/.cabal/libs/:$PATH"
$ cabal --v
cabal-install version 1.22.2.0
太好了。
4. Try it out again:
$ cabal sandbox init
Writing a default package environment file to
.../cabal.sandbox.config
Creating a new sandbox at .../.cabal-sandbox
$ cabal install Frames
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: Frames-0.1.2.1 (user goal)
next goal: base (dependency of Frames-0.1.2.1)
rejecting: base-4.6.0.1/installed-8aa... (conflict: Frames => base>=4.7 &&
<4.9)
rejecting: base-4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1,
4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2,
4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global constraint
requires installed instance)
Dependency tree exhaustively searched.
Note: when using a sandbox, all packages are required to have consistent
dependencies. Try reinstalling/unregistering the offending packages or
recreating the sandbox.
哦,所以base不兼容,好的。
$ cabal install base --reinstall
Resolving dependencies...
cabal: Could not resolve dependencies:
next goal: base (user goal)
rejecting: base-4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1,
4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2,
4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0 (only already installed instances can be
used)
rejecting: base-3.0.3.2 (conflict: base => base>=4.0 && <4.3)
rejecting: base-3.0.3.1 (conflict: base => base>=4.0 && <4.2)
Dependency tree exhaustively searched.
Note: when using a sandbox, all packages are required to have consistent
dependencies. Try reinstalling/unregistering the offending packages or
recreating the sandbox.
哎呀,那么所有的依赖关系怎么办?
$ cabal install --upgrade-dependencies
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: Frames-0.1.2.1 (user goal)
next goal: base (dependency of Frames-0.1.2.1)
rejecting: base-4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0 (global
constraint requires installed instance)
rejecting: base-4.6.0.1/installed-8aa... (conflict: Frames => base>=4.7 &&
<4.9)
rejecting: base-4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0,
4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global
constraint requires installed instance)
Dependency tree exhaustively searched.
Note: when using a sandbox, all packages are required to have consistent
dependencies. Try reinstalling/unregistering the offending packages or
recreating the sandbox.
看起来我无法重新安装/注销有问题的软件包。我希望错误信息能够给我更多关于如何做到这一点的提示,因为"--reinstall"标志是我最好的选择。
好吧,它提供了两个解决方案,那么让我们尝试另一个方法,重新创建沙盒。
$ cabal sandbox delete
Deleting the sandbox located at .../.cabal-sandbox
$ cabal sandbox init
Writing a default package environment file to
.../cabal.sandbox.config
Creating a new sandbox at .../.cabal-sandbox
$ cabal install --upgrade-dependencies
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: Frames-0.1.2.1 (user goal)
next goal: base (dependency of Frames-0.1.2.1)
rejecting: base-4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0 (global
constraint requires installed instance)
rejecting: base-4.6.0.1/installed-8aa... (conflict: Frames => base>=4.7 &&
<4.9)
rejecting: base-4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0,
4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global
constraint requires installed instance)
Dependency tree exhaustively searched.
Note: when using a sandbox, all packages are required to have consistent
dependencies. Try reinstalling/unregistering the offending packages or
recreating the sandbox.
这也没什么帮助。我已经没有思路了。我应该如何使用沙盒?我的理解是有一个全局变量导致了问题。按照沙盒的设计,全局变量不应该对它造成影响,对吧?
如果需要上下文,请注意,我只是尝试运行“Frames”的演示:
https://github.com/acowley/Frames
……它是:
$ cabal sandbox init
$ cabal install --dependencies-only -f demos # <-- here
我看到这一步有一个已关闭的问题,但那似乎是另一个问题。
base
与 GHC 的版本密切相关。由于您的 Cabal 是 1.16,我猜您正在使用 GHC 7.6.x,这在旧版 Linux LTS 发行版(如 Ubuntu 14.04)中很常见。请尝试使用 hvr 的ghc-x.y.z
包(在 launchpad 上),或者改用stack
,或者获取更新的版本。如果你不想切换 GHC 版本,则至少需要 GHC 7.8.x 才能运行 Frames。 - Zetahaskell-platform
debs 并存(只有ghc
的符号链接等会被覆盖),您可以在 cabal 中使用-w
标志来使用不同版本的 GHC(因此在 cabal 项目中使用base
)。但是,正如 zeta 建议的那样,您应该使用stack
;它听起来更加用户友好,并且可以处理安装 ghc。 - jberryman