Mit*_*ops 4 haskell cabal cabal-install cabal-sandbox
复制下面的任何命令是不明智的,不要执行它们.请查看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
Run Code Online (Sandbox Code Playgroud)
哦,亲爱的,这是旧的,不会运行沙盒.
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
Run Code Online (Sandbox Code Playgroud)
看起来不错.
3. Try it out:
$ cabal sandbox init
cabal: unrecognised command: sandbox (try --help)
Run Code Online (Sandbox Code Playgroud)
嗯.
$ which cabal
/usr/bin/cabal
Run Code Online (Sandbox Code Playgroud)
啊.
$ ${HOME}/.cabal/bin/cabal --version
cabal-install version 1.22.2.0
using version 1.22.2.0 of the Cabal library
Run Code Online (Sandbox Code Playgroud)
啊哈.
$ export PATH="${HOME}/.cabal/bin/:$PATH"
$ export PATH="${HOME}/.cabal/libs/:$PATH"
$ cabal --v
cabal-install version 1.22.2.0
Run Code Online (Sandbox Code Playgroud)
大.
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.
Run Code Online (Sandbox Code Playgroud)
嗯,所以基地不兼容,好的.
$ 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.
Run Code Online (Sandbox Code Playgroud)
嗯,所有依赖项呢?
$ 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.
Run Code Online (Sandbox Code Playgroud)
似乎我无法重新安装/取消注册有问题的软件包.我希望错误消息能给我一些关于如何做到这一点的更多信息,因为"--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.
Run Code Online (Sandbox Code Playgroud)
这也没有帮助.新鲜的想法.我该如何使用沙箱?我在这里读到的是一个引起问题的全球性问题.沙箱的设计不应该被沙箱打扰,对吧?
如果它有助于上下文,我只是尝试运行Frames的演示:
https://github.com/acowley/Frames
......这是:
$ cabal sandbox init
$ cabal install --dependencies-only -f demos # <-- here
Run Code Online (Sandbox Code Playgroud)
我看到这一步有一个封闭的问题,但这似乎是一个不同的问题.
该版本与baseGHC版本紧密耦合.例如,base-4.6.0.1GHC 7.6.3的船舶.您不能使用具有不兼容的GHC版本的其他版本的base.为了使用base-4.7.0.x,你需要GHC 7.8.x.
因此,您无法使用本地沙箱base.它是无法获取沙盒的(极少数)软件包之一.
如果我们采用沙盒的比喻概念,我们很快就会看到沙盒需要某种基础.而这正是base.其他所有东西都可以存在于沙箱中,应该可以工作:
我该如何使用沙箱?
您正确使用沙箱,但没有安装正确的编译器/库.
我不明白为什么cabal让我升级到一个如此不一致的状态我什么也做不了.
同样,Cabal并不处于不一致的状态.Frames限制最小基本版本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
Run Code Online (Sandbox Code Playgroud)
如果这样可行,则baseFrames 的下限实际上太高,您可以在库上提交pull-request.
现在有四种方法可供选择.按难度递减顺序:
apt-getLTS发行版中的包通过).stack setup(最简单的一个).我将专注于MinGHC和Stack one,因为它们提供了简单的方法来相互安装几个GHC版本.
基本上按照本网站上的说明进行操作.在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
Run Code Online (Sandbox Code Playgroud)
这使您可以轻松安装其他版本的cabal和GHC
sudo apt-get install -y cabal-install-1.xx ghc-7.yy.z
Run Code Online (Sandbox Code Playgroud)
然后更改您的PATH变量.然后,您可以使用cabal sandbox *命令.
我还建议你阅读斯蒂芬迪尔关于卡巴尔的笔记.它们提供了一些常用功能的深入见解.
再次按照本网站上的说明操作.它基本相同:您添加外部源并告诉您的发行版信任这些来源:
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
Run Code Online (Sandbox Code Playgroud)
之后,您必须stack init在已有的Cabal项目中使用,或者stack new安装一个新项目,然后stack setup安装一个相当新版本的GHC:
$ stack new my-project
$ cd my-project
$ stack setup
# Loooooooooooooooooooooooong log, installs GHC in background
Run Code Online (Sandbox Code Playgroud)
请注意,stack以"理智"的方式安装所有依赖项.它使用内部LTS系统,您不必使用cabal沙箱.但是,您不能再使用Cabal命令,而是必须使用stack build或stack ghc.
如果你不使用包,就像
stack ghc --package Frames -- -O2 --make -rtsopts File1.hs File2.hs
Run Code Online (Sandbox Code Playgroud)
是可能的.但是,记录堆栈的每个功能都会破坏这个答案的范围并很快就会过时,所以看看文档.