【问题标题】:Pandoc 'Could not find module ...' for installed module已安装模块的 Pandoc '找不到模块 ...'
【发布时间】:2014-01-22 02:31:15
【问题描述】:

我目前正在尝试使用 pandoc(作为 Haskell 模块,而不是作为程序)将 MediaWiki 文本转换为其他格式。

让我们假设这个程序:

 import Text.Pandoc.Readers.MediaWiki
 main = do print "foo"

使用runghc 运行它时,我收到以下错误消息:

pandock.hs:1:8:
    Could not find module `Text.Pandoc.Readers.MediaWiki'
    Use -v to see a list of the files searched for.

我的第一个假设是 pandoc 要么没有安装,要么安装不正确。因此我用--force-reinstalls重新安装了它

$ cabal install pandoc --reinstall
[...]
In order, the following will be installed:
pandoc-1.12.3.1 (reinstall) changes: old-time-1.1.0.1 added
[...]
[32 of 55] Compiling Text.Pandoc.Readers.MediaWiki ( src/Text/Pandoc/Readers/MediaWiki.hs, dist/build/Text/Pandoc/Readers/MediaWiki.o )
[...]
Installing library in
/home/uli/.cabal/lib/x86_64-linux-ghc-7.6.3/pandoc-1.12.3.1
Installing executable(s) in /home/uli/.cabal/bin
Registering pandoc-1.12.3.1...
Installed pandoc-1.12.3.1

runghc -v pandock.hs 的输出很长,我假设相关部分是:

*** Chasing dependencies:
Chasing modules from: *pandock.hs

pandock.hs:1:8:
    Could not find module `Text.Pandoc.Readers.MediaWiki'
    Locations searched:
      Text/Pandoc/Readers/MediaWiki.hs
      Text/Pandoc/Readers/MediaWiki.lhs
Failed, modules loaded: none.

但是,~/.cabal/lib/x86_64-linux-ghc-7.6.3/pandoc-1.12.3.1/Text/Pandoc/Readers/Mediawiki/MediaWiki.hi~/.cabal/bin/pandoc 都存在。如何让 GHC 正确识别 cabal-installed 包?

任何帮助将不胜感激!

【问题讨论】:

  • 您的 pandoc 安装在全局还是用户包数据库中?我相信runghc 只会在其中一个数据库中查找。
  • @user2407038 我没有使用cabal install --global 安装,所以我可以假设它在用户数据库中吗?我以相同的方式安装并定期使用了几十个其他软件包(cabal install pandoc),其中任何一个都没有问题(包括,例如 Yesod)。
  • pandock.hs所在的位置,你正在调用runghc,你有没有子目录叫做TextText/Pandoc
  • @kosmikus 不幸的是,没有 :-( 它是一个空目录(我特别注意这一点,因为我遇到了类似的问题,Python 没有找到 Tornado,因为文件名为 tornado.py)
  • @MigMit 是的,确实如此(ghc-pkg list | grep pandoc 产生 pandoc-1.12.3.1)。我目前面临与yaml 包完全相同的问题,因此它似乎并不特定于pandoc。我也尝试在另一台计算机上重现该问题,但没有成功。 ghc-pkg check 显示一些损坏的包,可能问题与它们有关?

标签: haskell ghc cabal pandoc


【解决方案1】:

尝试在其他计算机上重现此问题时,只有五分之二的计算机出现此问题。在他们两个上,我以大致相同的方式和顺序安装了 cabal 包。

回想起来,我认为这个问题是由于一些损坏的包造成了严重破坏:

$ ghc-pkg check
There are problems in package feed-0.3.9.2:
  dependency "xml-1.3.13-dd52b1688e97a3c6cd0aa48dba7b153e" doesn't exist
There are problems in package hxt-9.3.1.3:
  dependency "network-2.4.2.2-ea77cdf1bc747bc58308fdeb52745c4d" doesn't exist
There are problems in package hspec-1.8.1.1:
  dependency "QuickCheck-2.6-409fcc32c191cd6e04afdebb15869820" doesn't exist
There are problems in package quickcheck-io-0.1.0:
  dependency "QuickCheck-2.6-409fcc32c191cd6e04afdebb15869820" doesn't exist
There are problems in package regex-compat-0.95.1:
  dependency "regex-base-0.93.2-2023953b859e6f91efe89733d2ef5421" doesn't exist
There are problems in package regex-posix-0.95.2:
  dependency "regex-base-0.93.2-2023953b859e6f91efe89733d2ef5421" doesn't exist
There are problems in package hxt-9.3.1.2:
  dependency "network-2.4.2.2-ea77cdf1bc747bc58308fdeb52745c4d" doesn't exist

The following packages are broken, either because they have a problem
listed above, or because they depend on a broken package.
feed-0.3.9.2
hxt-9.3.1.3
hspec-1.8.1.1
quickcheck-io-0.1.0
regex-compat-0.95.1
regex-posix-0.95.2
hxt-9.3.1.2
MissingH-1.2.0.2
yesod-test-1.2.1

请注意,pandocyaml(我在提出问题后安装它并且与 pandoc 存在完全相同的问题)都没有列出。

对于也有类似问题的用户,请确保:

  1. 软件包已安装,并且您不在任何未安装该软件包的沙箱中。

  2. 在您正在执行测试脚本的目录中,确保没有 Text/Pandoc 文件夹(或等效文件夹,具体取决于导致问题的包

  3. 使用runghc -v 运行您的测试脚本,检查它是否搜索正确的目录

  4. ghc-pkg list 列出已安装的包,并且没有包损坏(使用ghc-pkg check 检查)

我通过重命名 ~/.cabal~/.ghc 解决了我的问题。请注意,我这样做缺乏适当的解决方案,我认为你应该只作为最后的手段这样做。

【讨论】: