ghc error: hidden package, but it's actually exposed

ghc error: hidden package, but it's actually exposed

我正在尝试使用 Parsec 包。 当我 运行 ghc Main.hs 我收到错误消息:

Could not load module ‘Text.Parsec’
It is a member of the hidden package ‘parsec-3.1.14.0’.
You can run ‘:set -package parsec’ to expose it.

但是,包应该已经公开了:ghc-pkg list 给出

usr/lib/ghc/package.conf.d
    Agda-2.6.0.1
    Cabal-2.4.0.1
    ...
    parsec-3.1.13.0
    ...

我应该怎么做才能让 ghc 自动加载它?

完整的错误消息提到了包的两个版本:

ExpScanner.hs:13:1: error:
    Could not load module ‘Text.Parsec’
    It is a member of the hidden package ‘parsec-3.1.14.0’.
    You can run ‘:set -package parsec’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    It is a member of the hidden package ‘parsec-3.1.13.0’.
    You can run ‘:set -package parsec’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v to see a list of the files searched for.

ExpScanner.hs 是 Main 调用的模块。

ghc-pkg list的完整输出是

/usr/lib/ghc/package.conf.d
    Agda-2.6.0.1
    Cabal-2.4.0.1
    EdisonAPI-1.3.1
    EdisonCore-1.3.2.1
    GLURaw-2.0.0.4
    GLUT-2.7.0.15
    HTTP-4000.3.14
    HUnit-1.6.0.0
    ObjectName-1.1.0.1
    OpenGL-3.0.3.0
    OpenGLRaw-3.3.3.0
    QuickCheck-2.12.6.1
    STMonadTrans-0.4.3
    StateVar-1.1.1.1
    aeson-1.4.2.0
    array-0.5.3.0
    async-2.2.2
    attoparsec-0.13.2.2
    base-4.12.0.0
    base-compat-0.10.5
    binary-0.8.6.0
    blaze-builder-0.4.1.0
    blaze-html-0.9.1.1
    blaze-markup-0.8.2.2
    boxes-0.1.5
    bytestring-0.10.8.2
    call-stack-0.1.0
    case-insensitive-1.2.0.11
    containers-0.6.0.1
    data-hash-0.2.0.1
    deepseq-1.4.4.0
    directory-1.3.3.0
    dlist-0.8.0.6
    edit-distance-0.2.2.1
    equivalence-0.3.4
    erf-2.0.0.0
    exceptions-0.10.2
    fgl-5.7.0.1
    filepath-1.4.2.1
    fixed-0.2.1.1
    geniplate-mirror-0.7.6
    ghc-8.6.5
    ghc-boot-8.6.5
    ghc-boot-th-8.6.5
    ghc-compact-0.1.0.0
    ghc-heap-8.6.5
    ghc-prim-0.5.3
    ghci-8.6.5
    gitrev-1.3.1
    half-0.3
    hashable-1.2.7.0
    hashtables-1.2.3.3
    haskeline-0.7.4.3
    haskell-src-1.0.3.0
    hpc-0.6.0.3
    html-1.0.1.2
    ieee754-0.8.0
    integer-gmp-1.0.2.0
    integer-logarithms-1.0.3
    libiserv-8.6.3
    mtl-2.2.2
    murmur-hash-0.1.0.9
    network-2.8.0.1
    network-uri-2.6.1.0
    parallel-3.2.2.0
    parsec-3.1.13.0
    pretty-1.1.3.6
    primitive-0.6.4.0
    process-1.6.5.0
    random-1.1
    regex-base-0.93.2
    regex-compat-0.95.1
    regex-posix-0.95.2
    regex-tdfa-1.2.3.2
    rts-1.0
    scientific-0.3.6.2
    split-0.2.3.3
    stm-2.5.0.0
    strict-0.3.2
    syb-0.7.1
    tagged-0.8.6
    template-haskell-2.14.0.0
    terminfo-0.4.1.2
    text-1.2.3.1
    tf-random-0.5
    th-abstraction-0.2.11.0
    time-1.8.0.2
    time-locale-compat-0.1.1.5
    transformers-0.5.6.2
    transformers-compat-0.6.5
    unix-2.7.2.2
    unordered-containers-0.2.10.0
    uri-encode-1.5.0.5
    utf8-string-1.0.1.1
    uuid-types-1.0.3
    vector-0.12.0.3
    xhtml-3000.2.2.1
    zlib-0.6.2
/home/venanzio/.ghc/x86_64-linux-8.6.5/package.conf.d
    Cabal-3.2.0.0
    base16-bytestring-0.1.1.6
    base64-bytestring-1.0.0.3
    conway-0.1.0.0
    cryptohash-sha256-0.11.101.0
    echo-0.1.3
    ed25519-0.0.5.0
    hackage-security-0.6.0.1
    lukko-0.1.1.2
    resolv-0.1.2.0
    tar-0.5.1.1

这看起来像是全局安装与本地安装的问题。哦,它在您的 ghc-pkg list 输出中。您已经安装了多用户 ghc 和 single-user 已安装软件包列表。当您 运行 ghc 作为超级用户时,事情会起作用,因为他们不会看到您的本地 (per-user) 安装。

除非您使用工具为您管理环境,否则这会导致问题。 cabal 和 stack 都可以很好地处理这个问题。我更喜欢 cabal,因为它不需要哄骗就能与您预装的 GHC 一起工作,但这是过去引起宗教战争的问题。如果你有很好的资源来使用它,我不会反对堆栈。