LoginSignup
23
21

More than 5 years have passed since last update.

GitHubリポジトリのブランチを指定して pip install する

Posted at

概要

GitHub リポジトリのうち、作業ブランチで開発中のパッケージを直接ローカルに pip install するときのコマンドの書き方を記します。

問題点として

GitHub から直接 pip install できる便利機能があるものの、公式ドキュメントや pip のドキュメントをよく見ないと書き方がわかりづらい。

pip install の書き方

URLスキーム pip コマンド
HTTPS pip install git+https://github.com/(アカウント名)/(リポジトリ名).git@(ブランチ名)
SSH pip install git+ssh://git@github.com/(アカウント名)/(リポジトリ名).git@(ブランチ名)

インストール例

例として下記のような作業ブランチを持つ GitHub リポジトリのうち、 develop ブランチの最新版をGitHubから直接インストールする方法を記します。

ブランチの構成

  d-------d  develop ブランチ
 /
o----------  master ブランチ

setup.py の書き方

この場合の setup.py の内容は通常のパッケージの書き方と同じです。

サンプルプログラムの作業ブランチを GitHub から直接 pip install する

GitHub サプリディレクトリを直接 pip install が行える実験用のサンプルプログラムを作成しました。

pip install コマンド

$ pip install "git+https://github.com/smn-ailab/tshimura_qiita.git@develop#egg=weather&subdirectory=weather_checker"
  • リポジトリ名.git の後に @ブランチ名 のかたちで指定します。
  • ここではサブディレクトリを指定するための subdirectory を追加し、その場合に必要になるダブルクォーテーションマークを全体に囲っています。 サブディレクトリのインストールの詳細記事はこちら
  • なおアンインストールは pip uninstall weather です。

参考

23
21
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
23
21