MacOS:在 High Sierra 上 brew install graph-tool

MacOS: brew install graph-tool on High Sierra

我正在使用 High Sierra,无法通过 brew install 安装 graph-tool。下面给出的是 brew 安装后的输出。

> brew install graph-tool
graph-tool: macOS Mojave or newer is required.
Error: An unsatisfied requirement failed this build.

由于我使用的是有点锁定的机器,我无法更新到 Mojave。我以前能够 brew install graph-tool 在 High Sierra 上毫无问题。

homebrew formulae link for graph-tool 似乎声明它现在仅适用于 Mojave。公式本身也是如此。

https://github.com/Homebrew/homebrew-core/blob/master/Formula/graph-tool.rb

depends_on :macos => :mojave # for C++17

有没有办法在我的机器上安装旧版本的图形工具?


更新

这可能不适用于大多数人。但是由于安装 graph_tool 如此费力,我想我应该在此处复制我的解决方案。

在尝试 bfontaine 的解决方案时,我不断收到以下错误:

==> /usr/local/Cellar/graph-tool/2.27_7/libexec/bin/pip install -v --no-deps --no-binary :all: --ignore-installed /private/tmp/graph-tool--matplotlib-20190621-40984-1767uhv/matplotlib-2.2.2

Last 15 lines from /Users/greatora/Library/Logs/Homebrew/graph-tool/05.pip:
Removed build tracker '/private/tmp/pip-req-tracker-b74drkg2'
ERROR: Command "/usr/local/Cellar/graph-tool/2.27_7/libexec/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/tmp/pip-req-build-6ib3tzd9/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/tmp/pip-record-8ubg3x4_/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/Cellar/graph-tool/2.27_7/libexec/bin/../include/site/python3.7/matplotlib" failed with error code 1 in /private/tmp/pip-req-build-6ib3tzd9/
Exception information:
Traceback (most recent call last):
  File "/usr/local/Cellar/graph-tool/2.27_7/libexec/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 178, in main
    status = self.run(options, args)
  File "/usr/local/Cellar/graph-tool/2.27_7/libexec/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 414, in run
    use_user_site=options.use_user_site,
  File "/usr/local/Cellar/graph-tool/2.27_7/libexec/lib/python3.7/site-packages/pip/_internal/req/__init__.py", line 58, in install_given_reqs
    **kwargs
  File "/usr/local/Cellar/graph-tool/2.27_7/libexec/lib/python3.7/site-packages/pip/_internal/req/req_install.py", line 951, in install
    spinner=spinner,
  File "/usr/local/Cellar/graph-tool/2.27_7/libexec/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 776, in call_subprocess
    % (command_desc, proc.returncode, cwd))
pip._internal.exceptions.InstallationError: Command "/usr/local/Cellar/graph-tool/2.27_7/libexec/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/tmp/pip-req-build-6ib3tzd9/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/tmp/pip-record-8ubg3x4_/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/Cellar/graph-tool/2.27_7/libexec/bin/../include/site/python3.7/matplotlib" failed with error code 1 in /private/tmp/pip-req-build-6ib3tzd9/

我意识到我不会使用图形工具的(优秀)功能进行可视化,所以我下载了 bfontaine 在下面链接的 graph_tool.rb 文件,从中删除了 matplotlib 依赖项,运行 brew install --build-from-source ~/Downloads/graph-tool.rb

然后我将 numpy 降级到 1.16.1,并且 graph_tool 按预期工作!

同样,仅当您不打算使用 graph_tool 的可视化功能时才执行此操作

请参阅下面我修改后的 graph_tool.rb 文件。

class GraphTool < Formula
  include Language::Python::Virtualenv

  desc "Efficient network analysis for Python 3"
  homepage "https://graph-tool.skewed.de/"
  url "https://downloads.skewed.de/graph-tool/graph-tool-2.27.tar.bz2"
  sha256 "4740c69720dfbebf8fb3e77057b3e6a257ccf0432cdaf7345f873247390e4313"
  revision 7

  bottle do
    sha256 "4bf2967b707d3fa33dbb1d0f54d2cf18b33820754232883f9f53192dd1155ccc" => :mojave
    sha256 "7454e5ac93d90e1e0048df7e34e6069e36674597d495fb76e2a22494f5fb76c1" => :sierra
  end

  depends_on "pkg-config" => :build
  depends_on "boost"
  depends_on "boost-python3"
  depends_on "cairomm"
  depends_on "cgal"
  depends_on "google-sparsehash"
  depends_on "gtk+3"
  depends_on "librsvg"
  depends_on :macos => :el_capitan # needs thread-local storage
  depends_on "numpy"
  depends_on "py3cairo"
  depends_on "pygobject3"
  depends_on "python"
  depends_on "scipy"

  resource "Cycler" do
    url "https://files.pythonhosted.org/packages/c2/4b/137dea450d6e1e3d474e1d873cd1d4f7d3beed7e0dc973b06e8e10d32488/cycler-0.10.0.tar.gz"
    sha256 "cd7b2d1018258d7247a71425e9f26463dfb444d411c39569972f4ce586b0c9d8"
  end

  resource "kiwisolver" do
    url "https://files.pythonhosted.org/packages/31/60/494fcce70d60a598c32ee00e71542e52e27c978e5f8219fae0d4ac6e2864/kiwisolver-1.0.1.tar.gz"
    sha256 "ce3be5d520b4d2c3e5eeb4cd2ef62b9b9ab8ac6b6fedbaa0e39cdb6f50644278"
  end

  resource "pyparsing" do
    url "https://files.pythonhosted.org/packages/3c/ec/a94f8cf7274ea60b5413df054f82a8980523efd712ec55a59e7c3357cf7c/pyparsing-2.2.0.tar.gz"
    sha256 "0832bcf47acd283788593e7a0f542407bd9550a55a8a8435214a1960e04bcb04"
  end

  resource "python-dateutil" do
    url "https://files.pythonhosted.org/packages/a0/b0/a4e3241d2dee665fea11baec21389aec6886655cd4db7647ddf96c3fad15/python-dateutil-2.7.3.tar.gz"
    sha256 "e27001de32f627c22380a688bcc43ce83504a7bc5da472209b4c70f02829f0b8"
  end

  resource "pytz" do
    url "https://files.pythonhosted.org/packages/10/76/52efda4ef98e7544321fd8d5d512e11739c1df18b0649551aeccfb1c8376/pytz-2018.4.tar.gz"
    sha256 "c06425302f2cf668f1bba7a0a03f3c1d34d4ebeef2c72003da308b3947c7f749"
  end

  resource "six" do
    url "https://files.pythonhosted.org/packages/16/d8/bc6316cf98419719bd59c91742194c111b6f2e85abac88e496adefaf7afe/six-1.11.0.tar.gz"
    sha256 "70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9"
  end

  # Remove for > 2.27
  # Upstream commit from 3 Jul 2018 "Fix incompatibility with Python 3.7"
  patch do
    url "https://git.skewed.de/count0/graph-tool/commit/0407f41a.diff"
    sha256 "94559544ad95753a13ee701c02af706c8b296c54af2c1706520ec96e24aa6d39"
  end

  # Remove for > 2.27
  # Upstream commit from 3 Oct 2018 "Fix compilation with CGAL 4.13"
  patch do
    url "https://git.skewed.de/count0/graph-tool/commit/aa39e4a6.diff"
    sha256 "5a4ea386342c2de9422da5b07dd4272d47d2cdbba99d9b258bff65a69da562c1"
  end

  def install
    # Work around "error: no member named 'signbit' in the global namespace"
    ENV["SDKROOT"] = MacOS.sdk_path if MacOS.version == :high_sierra

    xy = Language::Python.major_minor_version "python3"
    venv = virtualenv_create(libexec, "python3")

    resources.each do |r|
      venv.pip_install_and_link r
    end

    args = %W[
      --disable-debug
      --disable-dependency-tracking
      --prefix=#{prefix}
      PYTHON=python3
      PYTHON_LIBS=-undefined\ dynamic_lookup
      --with-python-module-path=#{lib}/python#{xy}/site-packages
      --with-boost-python=boost_python#{xy.to_s.delete(".")}-mt
    ]
    args << "--with-expat=#{MacOS.sdk_path}/usr" if MacOS.sdk_path_if_needed

    system "./configure", *args
    system "make", "install"

    site_packages = "lib/python#{xy}/site-packages"
    pth_contents = "import site; site.addsitedir('#{libexec/site_packages}')\n"
    (prefix/site_packages/"homebrew-graph-tool.pth").write pth_contents
  end

  test do
    (testpath/"test.py").write <<~EOS
      import graph_tool as gt
      g = gt.Graph()
      v1 = g.add_vertex()
      v2 = g.add_vertex()
      e = g.add_edge(v1, v2)
      assert g.num_edges() == 1
      assert g.num_vertices() == 2
    EOS
    system "python3", "test.py"
  end
end

Graph-tool 2.28 requires macOS 莫哈韦沙漠。它已于 6 月 9 日在 Homebrew 中更新。您可以尝试通过使用直接 URL 到提交前的公式来安装以前的版本:

brew install --build-from-source https://raw.githubusercontent.com/Homebrew/homebrew-core/26177e166b/Formula/graph-tool.rb