Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup.py inside installed module

For a directory structure like the following, I haven't been able to make xy an importable package.

xy
├── __init__.py
├── z
│   ├── __init__.py
│   └── stuff.py
└── setup.py

If the setup.py were a directory up, I could use

from setuptools import setup
setup(name='xy',
      packages=['xy'])

but short of that, no combination of package_dir and packages has let me import xy, only import z. Unfortunately, moving the setup.py a directory up isn't really an option due to an excessive number of hard-coded paths.

like image 444
Alex Riina Avatar asked Nov 27 '25 14:11

Alex Riina


1 Answers

See the following answer for ideas how to use package_dir and packages to help with such projects: https://stackoverflow.com/a/58429242/11138259

In short for this case here:

#!/usr/bin/env python3
import setuptools
setuptools.setup(
    # ...
    packages=['xy', 'xy.z'],
    #packages=setuptools.find_packages('..')   # only if parent directory is otherwise empty
    package_dir={
        'xy': '.',
    },
)
like image 96
sinoroc Avatar answered Nov 30 '25 03:11

sinoroc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!