Conflict with Python Module Naming in Flake devShell

Hello everyone, I have a problem exposing two apps written in Python in a devShell declared in a flake. Both apps have a module with the same name “lib”, but this seems to create conflicts.

Here are the outputs of the flake.nix:

let
  app1 = pkgs.python3Packages.callPackage ./app1 { };
  app2 = pkgs.python3Packages.callPackage ./app2 { };
in
{
  packages.app1 = app1;
  packages.app2 = app2;

  devShells.default = pkgs.mkShell {
    packages = with pkgs; [
      app1
      app2
    ];
  };
}

Here are the derivations:

app1/default.nix

{ buildPythonApplication, pandas, setuptools, }:

buildPythonApplication rec {
  pname = "app1";
  version = "0.1.0";
  pyproject = true;

  src = ./.;

  build-system = [ setuptools ];

  dependencies = [ pandas ];

  doCheck = false;
}

app2/default.nix

{ buildPythonApplication, setuptools, plotly, }:

buildPythonApplication rec {
  pname = "app2";
  version = "0.1.0";
  pyproject = true;

  src = ./.;

  build-system = [ setuptools ];

  dependencies = [ plotly ];

  doCheck = false;
}

The apps are simple “Hello World” programs. The main file for both is identical:

import lib

def main():
    p = lib.Person()
    print(p.name())
    print(lib)

if __name__ == '__main__':
    main()

Modules

app1/lib/__init__.py


class Person:
    def name(self):
        return "Frank"

app2/lib/__init__.py


class Person:
    def name(self):
        return "Anna"

setup.py for both apps

app1/setup.py


setup(
  name='app1',
  packages=['lib'],
  version='0.1.0',
  author='',
  install_requires=install_requires,
  scripts=[
      'app1.py'
  ],
  entry_points={
    'console_scripts': ['app1=app1:main']
  },
)

app2/setup.py


setup(
  name='app2',
  packages=['lib'],
  version='0.1.0',
  author='',
  install_requires=install_requires,
  scripts=[
      'app2.py'
  ],
  entry_points={
    'console_scripts': ['app2=app2:main']
  },
)

When I try to run app2, it loads the “lib” module from app1:


λ app1
Frank
<module 'lib' from '/nix/store/kdsm5991239kdr2p0ipzk4jwk9jghlix-app1-0.1.0/lib/python3.12/site-packages/lib/__init__.py'>
λ app2
Frank
<module 'lib' from '/nix/store/kdsm5991239kdr2p0ipzk4jwk9jghlix-app1-0.1.0/lib/python3.12/site-packages/lib/__init__.py'>

Is there a way to prevent this and ensure that app2 correctly loads its own module?

λ app2
Anna
<module 'lib' from '/nix/store/gcdynkwv3hrffq1iks0lcxar6r5xi4yj-app2-0.1.0/lib/python3.12/site-packages/lib/__init__.py'>

Thank you very much!