Adam Matan
Adam Matan

Reputation: 136141

pip: install a package from a github source subdirectory

I am trying to install a Python package from a source directory in a github repo. With accordance to the Python Packaging Manual, The source directory contains a setup.cfg instead of the old setup.py.

Code

My code follows the Python Packaging Tutorial - a parent directory which contains the metadata, and a src subdirectory which contains a sub-subdirectory with the package itself with and __init__.py file. It's available on https://github.com/adamatan/github-packages-python.

Installing locally - either by building a local dist and wheel using python -m build, and installing the wheel with pip install <path_to_wheel>, or by installing the source using `pip install packaging_tutorial - works well.

.
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
└── packaging_tutorial
    ├── LICENSE
    ├── README.md
    ├── build_and_publish.sh
    ├── pyproject.toml
    ├── setup.cfg
    └── src
        └── example_package
            ├── __init__py
            └── example.py

What Have I Tried

SSH Install

pip install git+ssh://[email protected]/adamatan/github-packages-python.git#egg=packaging_tutorial

Collecting packaging_tutorial
  Cloning ssh://****@github.com/adamatan/github-packages-python.git to /private/var/folders/ty/43hxrncx4nl9n34kmq3w84300000gn/T/pip-install-oc4il6j7/packaging-tutorial_8d95646df03e40dab7f341209c8e71f5
  Running command git clone -q 'ssh://****@github.com/adamatan/github-packages-python.git' /private/var/folders/ty/43hxrncx4nl9n34kmq3w84300000gn/T/pip-install-oc4il6j7/packaging-tutorial_8d95646df03e40dab7f341209c8e71f5
ERROR: File "setup.py" not found for legacy project packaging_tutorial from git+ssh://****@github.com/adamatan/github-packages-python.git#egg=packaging_tutorial.

HTTPS install

pip install git+https://github.com/adamatan/github-packages-python.git#egg=packaging_tutorial
Collecting packaging_tutorial
  Cloning https://github.com/adamatan/github-packages-python.git to /private/var/folders/ty/43hxrncx4nl9n34kmq3w84300000gn/T/pip-install-sgke7nr1/packaging-tutorial_61f519a8caca48cea01fe22fd5438936
  Running command git clone -q https://github.com/adamatan/github-packages-python.git /private/var/folders/ty/43hxrncx4nl9n34kmq3w84300000gn/T/pip-install-sgke7nr1/packaging-tutorial_61f519a8caca48cea01fe22fd5438936
ERROR: File "setup.py" not found for legacy project packaging_tutorial from git+https://github.com/adamatan/github-packages-python.git#egg=packaging_tutorial.

My Question

How can I install the example_package package from its source on Github?

Upvotes: 4

Views: 2782

Answers (1)

Adam Matan
Adam Matan

Reputation: 136141

The solution is simple - I just had to use the subdirectory flag instead (or in addition to) the egg one.

So:

pip install git+ssh://[email protected]/adamatan/github-packages-python.git#subdirectory=packaging_tutorial

pip install git+https://github.com/adamatan/github-packages-python.git#subdirectory=packaging_tutorial

Or:

pip install "git+ssh://[email protected]/adamatan/github-packages-python.git#subdirectory=packaging_tutorial&egg=example-pkg-adamatan"

Quoting the manual:

pip looks at 2 fragments for VCS URLs:

egg: For specifying the “project name” for use in pip’s dependency resolution logic. eg: egg=project_name

subdirectory: For specifying the path to the Python package, when it is not in the root of the VCS directory. eg: pkg_dir

Upvotes: 5

Related Questions