0
0

More than 1 year has passed since last update.

DVCインストールエラー対処方法: fatal error: git2.h: No such file or directory

Posted at

はじめに

データセットのバージョン管理でDVCを利用しています。先日AWSのEC2インスタンスにインストールしようとしたら想定外のエラーが出て苦慮しました。その時の対応方法をtipsとして残しておきます。

エラー発生状況

サーバ環境は次の通りです。

  • EC2 Ubuntu Server 20.04 LTS
  • Python 3.8.10

この環境でpip経由でDVCをインストールを試みた際にエラーが発生しました。

DVCのインストール
pip install DVC
エラーメッセージ
  Building wheel for pygit2 (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /tmp/tmpkyfs_98m build_wheel /tmp/tmpmwd9eqhx
       cwd: /tmp/pip-install-j2c4g7kr/pygit2
  Complete output (66 lines):
  ・・・<中略>・・・
  In file included from src/blob.c:30:
  src/diff.h:33:10: fatal error: git2.h: No such file or directory
     33 | #include <git2.h>
        |          ^~~~~~~~
  compilation terminated.
  error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pygit2

DVCの依存パッケージであるpygit2のインストールができずにエラーとなっていました。この状態が発生した場合、pip install pygit2 を実行しても同じエラーメッセージが表示されます。このエラーがなぜ発生するのか、原因までは分かりませんでした。

エラー回避方法

aptリポジトリからのインストールで回避できました。実はDVCの公式ドキュメントにも掲載されているのですが、案外読み過ごしちゃいますので、こちらでも記載します。

aptリポジトリからのインストール
sudo wget https://dvc.org/deb/dvc.list -O /etc/apt/sources.list.d/dvc.list
wget -qO - https://dvc.org/deb/iterative.asc | gpg --dearmor > packages.iterative.gpg
sudo install -o root -g root -m 644 packages.iterative.gpg /etc/apt/trusted.gpg.d/
rm -f packages.iterative.gpg
sudo apt update
sudo apt install dvc

インストール完了後に以下のコマンドを入力して、バージョン番号が返ってくればインストール成功です。

dvc -V
0
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
0
0