Install from GitHub

Install from GitHub#

The steps we followed in the last section have led to an installable package. So far we have installed the package from a local repository. To make installation even easier for our users we will now set things up so they can install the package on GitHub. This is a good option for early development of the package. You can have an remotely installable package, without the need to make things more complicated by using PyPI.

As a reminder we have the following basic package structure:

analysis-package
├── analysis_package
│   ├── __init__.py
│   ├── model.py
│   ├── data
│   |   ├── model_data.csv
├── tests
│   ├── test_model.py
├── LICENSE
├── environment.yml
├── README.md
└── pyproject.toml

As a reminder that pyproject.toml is the key to allowing our package to be installed via pip.

To make this package installable on GitHub we need to create a GitHub repository and push our repository to it. The example repository for package-template is available here.

To install from GitHub we need to activate the Python environment that we wish to install into e.g.

conda activate hds_code

and then we issue the following command:

pip install git+https://github.com/health-data-science-OR/analysis-package@main

The below is an exert from the output generated by the modified pip install. It reveals how the process differs from the local install! In summary, the main branch of the repository is cloned to your local machine (stored in a temporary directory). Once the repository has been downloaded the normal pip install process proceeds along with dependency installation.

Collecting git+https://github.com/health-data-science-OR/package-template@main
  Cloning https://github.com/health-data-science-OR/package-template (to revision main) to /tmp/pip-req-build-raw3ilfx
  Running command git clone --filter=blob:none --quiet https://github.com/health-data-science-OR/package-template /tmp/pip-req-build-raw3ilfx
Resolved https://github.com/health-data-science-OR/package-template to commit cc91d307285b9f10f9cab8cc8290525d84637352
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting matplotlib>=3.1.3 (from analysis_package==0.1.0)

In general to use GitHub for installations we issue a modification of the following command:

pip install git+https://github.com/user/repo.git@branch_or_tag