【问题标题】:Haskell - can't find packageHaskell - 找不到包
【发布时间】:2018-11-28 20:43:53
【问题描述】:

我通过 cabal 安装了一个包:Data.Vector

但是当我尝试编译一个包含import Data.Vector 的程序时:

Drews-MacBook-Pro:Blokus-AI drewgross$ ghc --make -O2 -prof -auto-all playGame

Grid.hs:28:8:
    Could not find module `Data.Vector'
    Perhaps you meant
      Data.Tensor (from Tensor-1.0.0.1)
      Data.Functor (from base)
    Use -v to see a list of the files searched for.
Drews-MacBook-Pro:Blokus-AI drewgross$ 

我用来安装的命令是:

cabal install -p --reinstall --force-reinstalls vector

为了编译我的程序,我做了其他各种各样的事情,但没有任何效果。我真的很想删除所有内容,回到第一格并再次下载包。我该怎么做?

编辑:进一步调查表明可能有 2 个版本的 Data.Vector:0.10.0.1 和 0.9.1,也许它们以某种方式发生冲突?

编辑:ghc-pkg check 没有列出任何错误,但给了我大量如下所示的警告:

Warning: haddock-interfaces: /Users/drewgross/.cabal/share/doc/haskell-lexer-1.0/html/haskell-lexer.haddock doesn't exist or isn't a file

编辑:GCHi 也没有找到它

λ> import Data.Vector

<no location info>:
    Could not find module `Data.Vector'
    Perhaps you meant Data.Functor (from base)
λ> 

编辑:ghc-pkg list vector

Drews-MacBook-Pro:Blokus-AI drewgross$ ghc-pkg list vector
/Library/Frameworks/GHC.framework/Versions/7.4.2-x86_64/usr/lib/ghc-7.4.2/package.conf.d
/Users/drewgross/.ghc/x86_64-darwin-7.4.2/package.conf.d
   vector-0.10.0.1
Drews-MacBook-Pro:Blokus-AI drewgross$ 

并使用 -v 标志构建:

Drews-MacBook-Pro:Blokus-AI drewgross$ ghc --make -O2 -prof -auto-all -v playGame
Glasgow Haskell Compiler, Version 7.4.2, stage 2 booted by GHC version 7.4.2
Using binary package database: /usr/local/Cellar/ghc/7.4.2/lib/ghc-7.4.2/package.conf.d/package.cache
Using binary package database: /Users/drewgross/.ghc/x86_64-darwin-7.4.2/package.conf.d/package.cache
package Cabal-1.16.0.3-e689d8e77b2f476229954cd43b1737bd is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd directory-1.1.0.2-72e928d14fc50f31f7e6404839a15691 unix-2.5.1.1-29636eb78541401e8e00393ef5df097e
package Tensor-1.0.0.1-a8f1a59665c3ebc4867678a14fe1460f is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package binary-0.5.1.1-e62c39c3aba8093e9b9655a4a8d2bce9 is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd bytestring-0.10.0.1-9b03e69060669eabf0b20e150305c7be
package bmp-1.2.3.2-c7572ec2bbb802bfd93fed0953c61d5d is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd binary-0.5.1.1-e62c39c3aba8093e9b9655a4a8d2bce9 bytestring-0.10.0.1-9b03e69060669eabf0b20e150305c7be
package bytestring-0.10.0.1-9b03e69060669eabf0b20e150305c7be is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package ghc-paths-0.1.0.9-4e6c624a3431a4fa7630e4fb77be4c83 is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package haskell-lexer-1.0-8fea1c35b626a2de761522690a88c063 is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package primitive-0.4.1-0007d441db5f4ce1ffd66bd3816c2d4e is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package split-0.2.1.1-03ec5738edb34f2e8967d25637b9392f is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package vector-0.10.0.1-3450daae3d9f2092020075d05481123c is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd primitive-0.5.0.1-15cdc8c11a54a78809b647af0c2975b3
wired-in package ghc-prim mapped to ghc-prim-0.2.0.0-7d3c2c69a5e8257a04b2c679c40e2fa7
wired-in package integer-gmp mapped to integer-gmp-0.4.0.0-af3a28fdc4138858e0c7c5ecc2a64f43
wired-in package base mapped to base-4.5.1.0-47f48c3ae7f8256a66a23e9dfe22eefc
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.7.0.0-e109822dcbed82c43f9fa60194eb64b5
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: -fscc-profiling -static
*** Chasing dependencies:
Chasing modules from: *playGame.hs

Grid.hs:28:8:
    Could not find module `Data.Vector'
    Perhaps you meant Data.Functor (from base)
    Locations searched:
      Data/Vector.hs
      Data/Vector.lhs
*** Deleting temp files:
Deleting: 
*** Deleting temp dirs:
Deleting: 
Drews-MacBook-Pro:Blokus-AI drewgross$ 

这是shell使用的:

Drews-MacBook-Pro:Blokus-AI drewgross$ which ghc
/usr/bin/ghc

我做了cabal install -v lens,显然有大量输出,但我认为这是相关部分:

Registering lens-3.7.0.2...
/usr/bin/ghc-pkg update - --global --user
Updating world file...
Drews-MacBook-Pro:Blokus-AI drewgross$ 

这似乎表明他们使用的是相同的版本。如果相关,我可以发布更多阴谋集团安装的输出。

编辑:来自 cabal install -v 的更多 ghc 输出

Building lens-3.7.0.2...
Preprocessing library lens-3.7.0.2...
Building library...
creating dist/build
/usr/bin/ghc --make -package-name lens-3.7.0.2 -hide-all-packages -fbuilding-cabal-package -i -idist/build -isrc -idist/build/autogen -Idist/build/autogen -Idist/build -optP-DTRUSTWORTHY=1 -optP-DDEFAULT_SIGNATURES=1 -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir dist/build -stubdir dist/build -package-id array-0.4.0.0-0b6c5ca7e879a14d110ca4c001dd9297 -package-id base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd -package-id bytestring-0.9.2.1-0044644a71adfe5e950e6c6f6ca13065 -package-id comonad-3.0.0.2-6ef27fce8536ebdf9c364307a0915f63 -package-id comonad-transformers-3.0-a6df581636b1c9b514cfa6560f17d6a3 -package-id comonads-fd-3.0-b906ed7898871c5d2427052e2eefa62e -package-id containers-0.4.2.1-75f143aa39a3e77a1ce2300025bdd8ce -package-id filepath-1.3.0.0-f998e5510c76a98913f57b14b4f16c57 -package-id ghc-prim-0.2.0.0-7d3c2c69a5e8257a04b2c679c40e2fa7 -package-id hashable-1.1.2.5-14291f3b4e96b5599759ce7daa2bd37c -package-id mtl-2.1.2-02e701f9b1590ee88a0b5b0bd5d93a29 -package-id parallel-3.2.0.3-4cdd6067624f867b253b98d6d9fb9f52 -package-id semigroups-0.8.4.1-4d3a86b037504e6000a0354510588745 -package-id split-0.2.1.1-03ec5738edb34f2e8967d25637b9392f -package-id template-haskell-2.7.0.0-29110cc89a711d6ab3e7ee0e0a8ee949 -package-id text-0.11.2.3-473d9a1761b27c7315f2ef4569d93c3c -package-id transformers-0.3.0.0-8e66ecc7d4dae2b07b2b5406908c70e4 -package-id unordered-containers-0.2.2.1-d70d5ccb1df11dbbbaac89571b1ee46d -package-id vector-0.10.0.1-3450daae3d9f2092020075d05481123c -O -Wall -fwarn-tabs -O2 -fdicts-cheap -funbox-strict-fields -XHaskell98 Control.Lens.TH Language.Haskell.TH.Lens Control.Exception.Lens Control.Lens Control.Lens.Action Control.Lens.Classes Control.Lens.Combinators Control.Lens.Fold Control.Lens.Getter Control.Lens.Indexed Control.Lens.IndexedGetter Control.Lens.IndexedFold Control.Lens.IndexedLens Control.Lens.IndexedSetter Control.Lens.IndexedTraversal Control.Lens.Internal Control.Lens.Internal.Zipper Control.Lens.Iso Control.Lens.Loupe Control.Lens.Plated Control.Lens.Prism Control.Lens.Representable Control.Lens.Setter Control.Lens.Simple Control.Lens.Traversal Control.Lens.Tuple Control.Lens.Type Control.Lens.WithIndex Control.Lens.Wrapped Control.Lens.Zipper Control.Lens.Zoom Data.Bits.Lens Data.ByteString.Lens Data.ByteString.Strict.Lens Data.ByteString.Lazy.Lens Data.Complex.Lens Data.Data.Lens Data.Dynamic.Lens Data.HashSet.Lens Data.IntSet.Lens Data.List.Lens Data.List.Split.Lens Data.Sequence.Lens Data.Set.Lens Data.Text.Lens Data.Text.Strict.Lens Data.Text.Lazy.Lens Data.Tree.Lens Data.Typeable.Lens Data.Vector.Lens Data.Vector.Generic.Lens GHC.Generics.Lens Data.Array.Lens System.FilePath.Lens Control.Parallel.Strategies.Lens Control.Seq.Lens Control.Lens.Internal.Combinators
[ 1 of 57] Compiling Control.Lens.Classes ( src/Control/Lens/Classes.hs, dist/build/Control/Lens/Classes.o )
[ 2 of 57] Compiling Control.Lens.Internal ( src/Control/Lens/Internal.hs, dist/build/Control/Lens/Internal.o )
[ 3 of 57] Compiling Control.Lens.Internal.Combinators ( src/Control/Lens/Internal/Combinators.hs, dist/build/Control/Lens/Internal/Combinators.o )
[ 4 of 57] Compiling Control.Lens.Indexed ( src/Control/Lens/Indexed.hs, dist/build/Control/Lens/Indexed.o )
[ 5 of 57] Compiling Control.Lens.IndexedGetter ( src/Control/Lens/IndexedGetter.hs, dist/build/Control/Lens/IndexedGetter.o )
[ 6 of 57] Compiling Control.Lens.Action ( src/Control/Lens/Action.hs, dist/build/Control/Lens/Action.o )
[ 7 of 57] Compiling Control.Lens.Setter ( src/Control/Lens/Setter.hs, dist/build/Control/Lens/Setter.o )

编辑:ghc-pkg 转储

Drews-MacBook-Pro:Blokus-AI drewgross$ ghc-pkg dump | grep "id: base"
id: base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd

【问题讨论】:

  • ghc-pkg list vector 告诉你什么,当你用-v 选项编译playGame 时你会得到更多有用的信息吗?
  • @DanielFischer 我添加了这些命令的输出

标签: haskell package cabal cabal-install


【解决方案1】:

您的包裹数据库严重损坏。 ghc -v 输出列出了十个由于缺少或递归依赖关系而无法使用的包,其中vector

package vector-0.10.0.1-3450daae3d9f2092020075d05481123c is unusable due to missing or recursive dependencies:
  base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd primitive-0.5.0.1-15cdc8c11a54a78809b647af0c2975b3

所有损坏的包都有一个共同点是缺少(?)依赖

base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd

在哪里

wired-in package base mapped to base-4.5.1.0-47f48c3ae7f8256a66a23e9dfe22eefc

使用的碱基具有不同的哈希值。

我不确定这是怎么发生的,据我所知,重新安装 base 是不可能的,但看起来你有两个 ghc-7.4.2 的示例,它们互相踩脚趾。

ghc-pkg list 使用

/Library/Frameworks/GHC.framework/Versions/7.4.2-x86_64/usr/lib/ghc-7.4.2/package.conf.d

为全局包数据库,而编译使用

Using binary package database: /usr/local/Cellar/ghc/7.4.2/lib/ghc-7.4.2/package.conf.d/package.cache

现在,可能两者中至少有一个是符号链接,并且它们都指向同一个地方 - 那么你的 package.cache 不同步 - 但是

Glasgow Haskell Compiler, Version 7.4.2, stage 2 booted by GHC version 7.4.2

由同一版本启动的 GHC 似乎不寻常。

你能确定你是否确实有两个 ghc-7.4.2 并且命令行使用了一个与 cabal 使用的不同的一个吗? which ghc 告诉你 shell 使用哪一个,cabal install -v some-package 输出命令行 cabal 使用,包括使用的 GHC 的整个路径。

【讨论】:

  • 我添加了这些程序的输出。他们似乎使用相同的 ghc。
  • 我想看一个编译命令行。来自/usr/binghc-pkg 表示它们使用相同,但我宁愿确定。
  • 好的,我添加了更多的编译内容。绝对似乎在使用/usr/bin/ghc
  • 确实如此。但是从命令行,我们可以读出 cabal-package-id base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd 传递给 ghc,因此它明确要求缺少(或者是它?)base 版本。现在的问题是,cabal 是从哪里得到的。正在调查。
  • @Drew 阴谋集团(和阴谋集团)的来源太大了,我无法确定,但阴谋集团似乎使用ghc-pkg dump 来找出可用的东西。您可以通过ghc-pkg dump | grep "id: base" 查看报告的基本版本(特别是 ABI 哈希)吗?
【解决方案2】:

您可以使用ghc-pkg list 列出已安装的软件包。例如(显然我需要更新),

$ ghc-pkg list | grep vector
    vector-0.9.1
    vector-algorithms-0.5.4
    vector-algorithms-0.5.4.2
    vector-space-0.8.0
    vector-strategies-0.3

您可以使用ghc-pkg unregister 取消注册它们。例如,

$ ghc-pkg unregister vector-0.9.1

然后cabal update &amp;&amp; cabal install vector 应该从 hackage 获取最新版本。

【讨论】:

  • 似乎没有用。每一步都很顺利,但最后还是找不到Data.Vector
  • 如果你打开 GHCi 并输入import Data.Vector,会发生什么吗?
  • GHCi 也找不到(添加到问题中)
【解决方案3】:

在现有(自制)ghc 安装 [Mac OS Mavericks 10.9.+] 上安装 Haskell 平台后,我在另一个模块上遇到了类似问题。我用自制软件卸载了以前的 ghc

brew uninstall ghc

并重新运行 Haskell 平台安装程序(Mac 上的 .pkg)。然后我不得不

sudo ghc-pkg recache

解决过期警告

ghc-pkg list

这解决了我的问题。

【讨论】:

    【解决方案4】:

    您可能希望将包添加到您的 .cabal 文件中

    【讨论】:

      猜你喜欢
      • 2014-03-02
      • 1970-01-01
      • 2013-08-05
      • 2013-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-15
      • 2017-07-27
      相关资源
      最近更新 更多