パンうめぇ

園児ニアの日記帳

gnuplotがお亡くなりになられた

MacOSをMojave(16.14.2)にアプデした後,gnuplotでpdfを生成したかったので再インストールしようとして沼った事件.

% brew uninstall gnuplot
uninstall gnuplot
Uninstalling /usr/local/Cellar/gnuplot/5.2.6_1... (48 files, 2.9MB)

% brew install gnuplot --with-aquaterm --with-x11 --with-pdf
Usage: brew install [options] formula

Install formula.

formula is usually the name of the formula to install, but it can be specified
in several different ways.
:
:
Error: invalid option: --with-aquaterm

--withなんとかとかいうオプションがないと怒られる.aqua termだけかと思ったけどそうでもないっぽいです.

brew infoでオプションを調べてみると

% brew info gnuplot
:
==> Options
--HEAD
    Install HEAD version
:

HEADしかないやーん.

しかたないのでオプションなしでインストールします.

% brew install gnuplot

起動します.

gnuplot

    G N U P L O T
    Version 5.2 patchlevel 6    last modified 2019-01-01 

    Copyright (C) 1986-1993, 1998, 2004, 2007-2018
    Thomas Williams, Colin Kelley and many others

    gnuplot home:     http://www.gnuplot.info
    faq, bugs, etc:   type "help FAQ"
    immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'unknown'

set term aqua
         ^
unknown or ambiguous terminal type; type just 'set terminal' for a list

WARNING: Error during initialization

aqua termがsetされない...

とりあえずpdfで出力できればいいので以下のように実行.

gnuplot> set terminal pdf

Terminal type is now 'pdfcairo'
Options are ' transparent enhanced fontscale 0.5 size 5.00in, 3.00in '
gnuplot> set output 'sin_graph.pdf'
gnuplot> plot sin(x)
         Can't plot with an empty y range!

y rangeが空だと怒られました.なぜ〜

そこから色々調べて以下を試してみました.

  • aqua termを再インストール
  • x11を再インストール
  • 他の環境(ubuntu)でインストール
  • PCを再起動
  • 自分でbuildしてmakeインストール
  • zshrcでpath設定を確認

しかし全部だめでしたorz 同じようなエラーがでます.

他の環境でも同様の症状がでるからgnuplot側がおかしい...?

だが俺たちにはDokcerがある.

こちらを使わせていただきました.

github.com

cloneしてまずpltファイルを作成.sin(x)カーブを出力してみます.

  • sinx.plt
set terminal pdf
set output 'sin_graph.pdf'
plot sin(x)

terminalで以下のように実行.(docker for macをインストールする必要があります)

$ docker run --rm --volume $(pwd):/tmp -w /tmp pavlov99/gnuplot gnuplot sinx.plt

無事pdfファイルが生成されました.

f:id:kanekou:20190204154834p:plain
出力されたsin(x)

どっかー神.gnuplotはアップデートで直ってくれ〜頼む(人∀・)

追記(2019/02/11)

コメントでid:ooiw-r-5-0307さんよりアドバイスを頂き,実行したところgnuplotが無事に起動しました!!

方法としては, /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gnuplot.rbのコピーを取って,

% sudo cp /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gnuplot.rb /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gnuplot_backup.rb

以下のように書き換えました.

class Gnuplot < Formula
  desc "Command-driven, interactive function plotting"
  homepage "http://www.gnuplot.info/"
  url "https://downloads.sourceforge.net/project/gnuplot/gnuplot/5.2.6/gnuplot-5.2.6.tar.gz"
  sha256 "35dd8f013139e31b3028fac280ee12d4b1346d9bb5c501586d1b5a04ae7a94ee"
  revision 1

  bottle do
    rebuild 1
    sha256 "47903eca8637b8de9b803932795fe9dec4a45df4ea8ab61c51e2692501edce03" => :mojave
    sha256 "24a6c735fb69f8f7f016cf4ecadbe8d11022523c9d7160ef03160f41bf117aa7" => :high_sierra
    sha256 "5ef8fe2bebfcc2232f8ee414f0ce0c6b13482e212938d041dc55db7ea139eb10" => :sierra
  end

  head do
    url "https://git.code.sf.net/p/gnuplot/gnuplot-main.git"

    depends_on "autoconf" => :build
    depends_on "automake" => :build
    depends_on "libtool" => :build
  end

  option "with-aquaterm", "Build with AquaTerm support"
  option "with-wxmac", "Build with wxmac support"

  deprecated_option "qt" => "with-qt"
  deprecated_option "with-qt5" => "with-qt"
  deprecated_option "with-x" => "with-x11"
  deprecated_option "wx" => "with-wxmac"

  depends_on "pkg-config" => :build
  depends_on "gd"
  depends_on "lua"
  depends_on "pango"
  depends_on "readline"
  depends_on "qt" => :optional
  depends_on "wxmac" => :optional
  depends_on :x11 => :optional

  needs :cxx11 if build.with? "qt"

  resource "libcerf" do
    url "http://apps.jcns.fz-juelich.de/src/libcerf/libcerf-1.5.tgz"
    mirror "https://www.mirrorservice.org/sites/distfiles.macports.org/libcerf/libcerf-1.5.tgz"
    sha256 "e36dc147e7fff81143074a21550c259b5aac1b99fc314fc0ae33294231ca5c86"
  end

  def install
# Qt5 requires c++11 (and the other backends do not care)
    ENV.cxx11 if build.with? "qt"

    if build.with? "aquaterm"
# Add "/Library/Frameworks" to the default framework search path, so that an
# installed AquaTerm framework can be found. Brew does not add this path
# when building against an SDK (Nov 2013).
      ENV.prepend "CPPFLAGS", "-F/Library/Frameworks"
      ENV.prepend "LDFLAGS", "-F/Library/Frameworks"
    end

# gnuplot is not yet compatible with More recent libcerf:
# https://sourceforge.net/p/gnuplot/bugs/2077/
# In next release, we can remove this and depend on the libcerf formula.
    resource("libcerf").stage do
      system "./configure", "--prefix=#{buildpath}/libcerf", "--enable-static", "--disable-shared"
      system "make", "install"
    end
    ENV.prepend_path "PKG_CONFIG_PATH", buildpath/"libcerf/lib/pkgconfig"

    args = %W[
--disable-dependency-tracking
--disable-silent-rules
--prefix=#{prefix}
--with-readline=#{Formula["readline"].opt_prefix}
--without-tutorial
]

    args << "--disable-wxwidgets" if build.without? "wxmac"
    args << (build.with?("aquaterm") ? "--with-aquaterm" : "--without-aquaterm")
    args << (build.with?("qt") ? "--with-qt" : "--with-qt=no")
    args << (build.with?("x11") ? "--with-x" : "--without-x")

    system "./prepare" if build.head?
    system "./configure", *args
    ENV.deparallelize # or else emacs tries to edit the same file with two threads
    system "make"
    system "make", "install"
  end

  def caveats
    if build.with? "aquaterm"
      <<~EOS
AquaTerm support will only be built into Gnuplot if the standard AquaTerm
package from SourceForge has already been installed onto your system.
If you subsequently remove AquaTerm, you will need to uninstall and then
reinstall Gnuplot.
      EOS
    end
  end

  test do
    system "#{bin}/gnuplot", "-e", <<~EOS
set terminal dumb;
set output "#{testpath}/graph.txt";
plot sin(x);
    EOS
    assert_predicate testpath/"graph.txt", :exist?
  end
end

export HOMEBREW_NO_AUTO_UPDATE=1brewの自動アップデートを停止します.

gnuplotを再インストール.

% brew uninstall gnuplot
Uninstalling /usr/local/Cellar/gnuplot/5.2.6_1... (48 files, 2.9MB)
% brew install gnuplot --with-aquaterm
==> Downloading https://downloads.sourceforge.net/project/gnuplot/gnuplot/5.2.6/gnuplot-5.2.6.tar.gz
==> Downloading from https://nchc.dl.sourceforge.net/project/gnuplot/gnuplot/5.2.6/gnuplot-5.2.6.tar.gz
:
Error: Calling needs :cxx11 is disabled! There is no replacement.
Please report this to the caskformula/caskformula tap:
  /usr/local/Homebrew/Library/Taps/caskformula/homebrew-caskformula/Formula/inkscape.rb:49

If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
  https://github.com/caskformula/homebrew-caskformula/issues

少しErrorを吐いていますが, gnuplotを起動すると...

% gnuplot

    G N U P L O T
    Version 5.2 patchlevel 6    last modified 2019-01-01 

    Copyright (C) 1986-1993, 1998, 2004, 2007-2018
    Thomas Williams, Colin Kelley and many others

    gnuplot home:     http://www.gnuplot.info
    faq, bugs, etc:   type "help FAQ"
    immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'aqua'
Options are '0 title "Figure 0" size 846,594 font "Times-Roman,14" enhanced solid'
gnuplot>

正常に立ち上がりました! やったぜ!!

本当にありがとうございました.