LoginSignup
1
0

More than 3 years have passed since last update.

Modular versionのCASA 6.1をUbuntu 20.04に導入する

Last updated at Posted at 2021-04-29

TL;DL

電波天文学のソフトウェア CASA がpythonのモジュールとしてimportできるようになったので、Ubuntu 20.04に導入しようとしたが、色々面倒臭かったので、後の遭難者のために記事にまとめておきます。
注:CASAは公式にはUbuntuをサポートしていません。

準備

pipenvで管理したいのでpipenvを導入しておく。
参考: Ubuntu18.04にPython3.8 + Pipenv環境を構築

Ubuntuのpython version管理はupdate-alternativesが便利。デフォルトをpython3.6にしておく。
参考: UbuntuでPythonのバージョンを変更する方法

libgfortran3の導入

CASA 6.1 (modular)はlibgfortran3が必要だが、Ubuntu 20.04ではサポートされていないため、aptでinstallしようとしても、そんなものはないと言われる。

そこで、libgfortran3の.debファイルを直接ダウンロードしてinstallしようとするが、今度はgcc-6がないと言われる。Ubuntu 20.04ではgcc-9を利用しているので、古いgccを入れる必要があるようだ。

結局、gcc-6-baseの導入 -> libgfortran3の導入でうまくいくことがわかった。

gcc-6-baseとlibgfortran3の導入
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-6/gcc-6-base_6.5.0-2ubuntu1~18.04_amd64.deb
wget http://ports.ubuntu.com/pool/universe/g/gcc-6/libgfortran3_6.5.0-2ubuntu1~18.04_arm64.deb

sudo apt install ./gcc-6-base_6.5.0-2ubuntu1~18.04_amd64.deb
sudo apt install ./libgfortran3_6.5.0-2ubuntu1~18.04_arm64.deb

これでlibgfortran3の導入完了です。

pipenvで仮想環境をつくる。

以下のようなPipfileを用意する。

Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[[source]]
url = "https://casa-pip.nrao.edu/repository/pypi-casa-release/simple"
verify_ssl = true
name = "casa"

[packages]
numpy = "*"
pandas = "*"
scipy = "*"
matplotlib = "*"
astropy = "*"
ipython = "*"
casatools = "*"
casatasks = "*"

[dev-packages]

[requires]
python_version = "3.6"

なお、casatoolsとcasatasksのversionを具体的に指定すればpython 3.7でも動くらしい。
(参考: Python 3.7になったGoogle ColabでCASAを動かしてみる)

次に同じディレクトリでpipenvで環境構築。

pipenvでCASA6.1が入ったpython仮想環境を構築
pipenv install
pipenv run ipython

ipython上でcasatoolsとcasatasksがエラーなくimportできれば成功です。お疲れ様でした。

ipython
In [1]: import casatools
In [2]: import casatasks

その他

Ubuntu 20.04に対応しているのはlibgfortran5だが、こちらはCASAのmoduleをimportするときに参照するlibgfortranが3じゃないと怒られてしまう。libgfortran.so.5のシンボリックリンクをlibgfortran.so.3として作るというよくある裏技も試してみたが、やっぱりだめで、どうしても古いlibgfortran3が必要らしい。

追記 (2021/05/01)

並列で走らせようとして、casampi packageを導入しようとしたが失敗。解決したら記事にします...。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0