【问题标题】:How to successfully install ubergraph如何成功安装ubergraph
【发布时间】:2019-04-04 22:27:29
【问题描述】:

首先我必须说,我对 clojure 完全陌生,所以如果我遗漏了一些明显的东西,请原谅我。 我最近在 atom 文本编辑器上安装了 clojure 包,以便创建一些图形,并尝试添加 ubergraph,这是一个使加权图形成为可能的扩展,因为标准 clojure 包不支持这些扩展。

我按照 ubergraphs github https://github.com/Engelberg/ubergraph 上的快速入门指南完成了第一步(将 ubergraph 添加到 leiningen 依赖项)。我下载了 git 存储库,不知道如何从这里继续。运行示例代码

(ns example.core
  (:require [ubergraph.core :as uber]))

(def graph1
  (uber/graph [:a :b] [:a :c] [:b :d]))

在 github 上描述的 repl 上最终出现以下错误:

CompilerException java.lang.NullPointerException, 编译:(ubergraph/core.clj:11:1)

在 core.clj 中似乎导致错误的行是:

(import-vars
 [...])

我跳过了 vars,因为我认为它们不会导致问题。 Clojure 在正确的版本 (1.9.0) 上运行并安装了 java 8。非常感谢您的帮助,在此先感谢。

【问题讨论】:

  • 我刚刚安装了库,创建了一个新的命名空间,将上面的代码粘贴到其中,它就可以工作了。它适用于我的 1.9.0 和 1.10.0。尝试运行lein clean
  • 试过了,没用。仍然返回相同的错误。你能发布你用来创建命名空间的代码吗?另外,我是否必须将库放在特定的地方?我可能在那里做错了什么。谢谢。
  • 我也尝试运行它 1.10.0,并得到几乎相同的东西:(ns example.core (:require [ubergraph.core :as uber])) Unexpected error (NullPointerException) macroexpanding potemkin.namespaces/import-def at (core.clj:11:1)
  • Running the example code on the repl - 你用的是哪个命令?
  • 它在下面描述,试图创建命名空间。

标签: clojure


【解决方案1】:

根据您的评论“另外,我必须将库放在特定的地方吗?”,这似乎是由于对如何安装库的误解造成的。你不应该手动处理这样的事情; leiningen 为您处理库安装。

这是一个快速指南,假设您尚未创建项目。如果有,请跳到第 2 步。

  1. 运行lein new app you-project-name-here。这将创建一个带有project.clj 和基本文件结构的准系统项目。如果您使用 IntelliJ+Cursive 之类的 IDE,创建新项目将自动执行此步骤。

  2. 进入您的project.clj,并将[ubergraph "0.5.2"] 添加到:dependencies 条目。作为一个最小的简化示例,它应该如下所示:

    (defproject example "0.1.0-SNAPSHOT"
        :dependencies [[org.clojure/clojure "1.10.0"]
                       [ubergraph "0.5.2"]]
    
        :main example.core) ; The path to your core
    
  3. 将您的core 设置为:

    (ns example.core
      (:require [ubergraph.core :as uber])
      (:gen-class))
    
    (def graph1
      (uber/graph [:a :b] [:a :c] [:b :d]))
    
    (defn -main
      "I don't do a whole lot ... yet."
      [& args]
      (println "The graph:" graph1))
    
  4. 现在运行lein run。您应该看到它下载了依赖项,然后打印出类似这样的混乱:

    The graph: {:node-map {:a #ubergraph.core.NodeInfo{:out-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :a, :dest :b, :mirror? false}}, :c #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :a, :dest :c, :mirror? false}}}, :in-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :b, :dest :a, :mirror? true}}, :c #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :c, :dest :a, :mirror? true}}}, :out-degree 2, :in-degree 2}, :b #ubergraph.core.NodeInfo{:out-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :b, :dest :a, :mirror? true}}, :d #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :b, :dest :d, :mirror? false}}}, :in-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :a, :dest :b, :mirror? false}}, :d #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :d, :dest :b, :mirror? true}}}, :out-degree 2, :in-degree 2}, :c #ubergraph.core.NodeInfo{:out-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :c, :dest :a, :mirror? true}}}, :in-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :a, :dest :c, :mirror? false}}}, :out-degree 1, :in-degree 1}, :d #ubergraph.core.NodeInfo{:out-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :d, :dest :b, :mirror? true}}}, :in-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :b, :dest :d, :mirror? false}}}, :out-degree 1, :in-degree 1}}, :allow-parallel? false, :undirected? true, :attrs {}, :cached-hash #object[clojure.lang.Atom 0x16da1abc {:status :ready, :val -1}]}
    

我怀疑 NPE 是因为您以某种方式安装了 ubergraph,但不允许它自动解决其依赖关系。当它试图运行 import-vals 时,它所依赖的库之一没有找到,它就崩溃了。

【讨论】:

  • 我按照你的建议做了,但不幸的是,我仍然在同一个地方遇到了 NPE。 but didn't allow it to automatically resolve its dependencies你知道如何解决这个问题吗?但是感谢您提供的简化教程,这已经帮助我更好地使用 clojure。
  • @heathcliff 尝试运行lein clean,或者手动删除之前手动安装的文件,然后再次尝试我写的内容。如果它发现您已经拥有 ubergraph,它可能不会尝试解决差异。
  • 好的,我重新安装了一切,它成功了! NPE 消失了,lein 将图形作为代码返回。感谢您到目前为止的帮助。现在,对于最后一部分,我希望 proto-repl 返回生成的图。但是在 repl 上运行新项目后,它什么也不返回,尽管它在终端中工作,如上所述。
  • 你是说在 REPL 中输入 (uber/graph [:a :b] [:a :c] [:b :d])) 没有任何作用吗?而且我从来没有使用过 Proto-repl,所以可能有一些我不知道的怪癖。
  • 在 github 上输入 (uber/pprint graph1) 返回 Syntax error compiling at (form-init3482870938599296850.clj:1:1). No such namespace: uber core.clj 似乎没有加载。
猜你喜欢
  • 2018-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-29
  • 1970-01-01
  • 1970-01-01
  • 2012-05-21
  • 1970-01-01
相关资源
最近更新 更多