iMind Developers Blog

iMind開発者ブログ

githubのプロジェクトをpip install

概要

pip installする際にgithubのmasterや任意のブランチからインストールしたい。

バージョン情報

  • pip 19.1.1

サンプルプロジェクト

helloworldと出力するだけの自前ライブラリを用意してgithubにpushしておく。

ディレクトリ構成

├── helloworld
│   └── __init__.py
└── setup.py

setup.py

# setup.py

from setuptools import setup, find_packages

setup(
    name='helloworld',
    version='1.0',
    packages=find_packages()
)

__init__.py

# __init__.py

def hello():
    print('hello 1.0')

こちらに置いた。

https://github.com/mwsoft/hellopipworld

cloneしてからインストール

対象のプロジェクトをcloneしてからpipでインストール。

$ git clone https://github.com/mwsoft/hellopipworld.git
$ cd hellopipworld
$ pip install .

githubのmasterから直接インストール

下記のような記述でgithubのmasterから直接pip installを実行することもできる。

$ pip install git+https://github.com/mwsoft/hellopipworld.git

ブランチからのインストール

v1.1というブランチがあった場合の記述例。

pip install -U git+https://github.com/mwsoft/hellopipworld.git@v1.1

プロジェクト内に複数のsetup.pyがいる場合

gitの直下にhelloworldがいて、別フォルダにsub_projという名前の別のライブラリがいる構成。

├── helloworld
│   └── __init__.py
├── setup.py
└── sub_proj
    ├── setup.py
    └── subhelloworld
        └── __init__.py

これをv1.2ブランチに入れた。

https://github.com/mwsoft/hellopipworld/tree/v1.2

sub_projをインストールする。

$ pip install git+https://github.com/mwsoft/hellopipworld.git@v1.2#subdirectory=sub_proj

後片付け

$ pip uninstall helloworld subhelloworld  

改定履歴

Author: Masato Watanabe, Date: 2019-06-02, 記事投稿