复制下面的任何命令是不明智的,不要执行它们.请查看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.
嗯,所以基地不兼容,好的.
$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”标志是我最好的镜头.
好吧,它提供了2个解决方案,所以让我们尝试另一个,重新创建沙箱.
$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
我看到这一步有一个closed issue,但这似乎是一个不同的问题.
在舞台后面看(或者:基地有什么特别之处)base的版本与GHC版本紧密耦合.例如,base-4.6.0.1附带GHC 7.6.3.您不能使用具有不兼容的GHC版本的其他版本的base.要使用base-4.7.0.x,需要GHC 7.8.x.
因此,您不能使用本地沙箱作为基础.它是无法获取沙盒的(极少数)软件包之一.
沙箱需要强大的基础
如果我们采用沙盒的比喻概念,我们很快就会看到沙盒需要某种基础.而这正是基础.其他所有东西都可以存在于沙箱中,应该可以工作:
How do I use sandbox?
您正确使用沙箱,但没有安装正确的编译器/库.
I don’t understand why cabal let me upgrade itself into a state so inconsistent I can’t do anything.
同样,Cabal并不处于不一致的状态.框架将最小基本版本限制为4.7,这通常意味着它使用GHC 7.8引入的GHC功能.即使你能够安装base-4.7.x.y,你仍然会错过那些GHC功能.
但是,建议不要使用最新版本的Cabal和旧版本的GHC.
尝试其他下限
但是,有时库有一个太严格的下限.也许Frames适用于GHC 7.6.你可以在本地检查:
$cabal unpack Frames $cd Frames-* $vim Frames.cabal # change the min base to something lower $cabal sandbox init $cabal build
如果这样可行,则Frames中base的下限实际上太高,您可以在库上提交pull-request.
在旧版本中获取新内容
现在有四种方法可供选择.按难度递减顺序:
>从GHC download page手动安装GHC和Cabal(不推荐,仅限有经验的用户).
>安装最小版本的GHC和Cabal,见MinGHC.
>手动安装最新版本的Haskell platform(不要忘记事先删除旧版本;使用shell脚本,而不是通过apt-get在LTS发行版上的包).
>安装stack并使用堆栈设置(最简单的一个).
我将专注于MinGHC和Stack one,因为它们提供了简单的方法来相互安装几个GHC版本.
MinGHC安装(特定于Linux)
基本上按照this site上的说明进行操作.在Ubuntu上,您必须向apt源添加第三方源并安装特定版本的Cabal和GHC.请注意,这会将GHC和Cabal安装到/ opt /,因此您必须在路径中添加一些目录:
sudo apt-get update sudo apt-get install -y software-properties-common sudo add-apt-repository -y ppa:hvr/ghc sudo apt-get update sudo apt-get install -y cabal-install-1.22 ghc-7.10.3 cat >> ~/.bashrc <<EOF export PATH="\$HOME/.cabal/bin:/opt/cabal/1.20/bin:/opt/ghc/7.10.3/bin:\$PATH" EOF export PATH=~/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:$PATH
这使您可以轻松安装其他版本的cabal和GHC
sudo apt-get install -y cabal-install-1.xx ghc-7.yy.z
然后更改PATH变量.之后,您可以使用cabal sandbox *命令.
我还建议你阅读Stephen Diel’s notes on Cabal.它们提供了一些常用功能的深刻见解.
使用堆栈
再次按照this site上的说明操作.它基本相同:您添加外部源并告诉您的发行版信任这些来源:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 575159689BEFB442 echo 'deb http://download.fpcomplete.com/ubuntu trusty main' | sudo tee /etc/apt/sources.list.d/fpco.list sudo apt-get update && sudo apt-get install stack -y
之后,您必须在已有的Cabal项目中使用stack init,或者使用stack new来安装新项目,然后进行堆栈设置,这将安装一个相当新版本的GHC:
$stack new my-project $cd my-project $stack setup # Loooooooooooooooooooooooong log, installs GHC in background
请注意,堆栈以“理智”的方式安装所有依赖项.它使用内部LTS系统,您不必使用cabal沙箱.但是,您不能再使用Cabal命令,而是必须使用堆栈构建或堆栈ghc.
如果你不使用包,就像
stack ghc --package Frames -- -O2 --make -rtsopts File1.hs File2.hs
是可能的.但是,记录堆栈的每个功能都会破坏这个答案的范围并很快就会过时,所以看看documentation.