Search code examples
pythongitpipsetuptoolssetup.py

Setup.py reinstalling already installed user-written package


I am developing two python packages, pkg_a and pkg_b. pkg_a is a requirement for pkg_b, and so the setup.py for pkg_b looks like this:

from setuptools import setup

inst_reqs = [
    'pkg_a @ git+ssh://[email protected]/vlad/pkg_a.git',
]

setup(
    name="pkg_b",
    version="0.0.0",
    packages=['pkg_b'],
    install_requires=inst_reqs,
)

Since I am developing both packages simultaneously, pkg_a is already installed in editable mode (pip install -e .).

When pip installing pkg_b, why is the existing installation of pkg_a removed? It looks like pip will systematically cone the specified repo, uninstall the existing pkg_a and reinstall it from the cloned repo:

Successfully built pkg_a
Installing collected packages: pkg_a, pkg_b
  Attempting uninstall: pkg_a
    Found existing installation: pkg_a 0.0.0
    Uninstalling pkg_a-0.0.0:
      Successfully uninstalled pkg_a-0.0.0
  Running setup.py develop for pkg_b
Successfully installed pkg_a-0.0.0 pkg_b

I'm guessing this has to with versioning but I don't know how to fix this. Any tips?


Solution

  • That is how VCS dependencies are handled. You should specify a fixed reference (tag, commit id):

    'pkg_a @ git+ssh://[email protected]/vlad/pkg_a.git@da39a3ee5e6b4b0d3255bfef95601890afd80709'
    

    See: https://pip.pypa.io/en/stable/reference/pip_install/#git

    If you do not specific a fixed reference (non-moving tag, or commit ID), then pip has to clone every time since the content of the repository might have changed since the last installation.

    (To be honest, even after this change, it might still be that pip will re-clone at each installation, I do not remember the exact behavior off the top of my head.)

    See similar question: pip install upgrade fail to upgrade private dependency