1

I am trying to access packages outside of the current package using setup.py. My project structure looks like this.

Example1/
|-- submodule1/
|   |-- __init__.py
|      |-- main/
|          |-- __init__.py
|          |-- hello.py
|   |-- setup.py
|-- submodule2/
|   |-- __init__.py
|      |-- main/
|          |-- __init__.py
|          |-- world.py
|   |-- setup.py
|-- submodule3/
|   |-- __init__.py
|      |-- main/
|          |-- __init__.py
|          |-- sample.py
|   |-- setup.py
|-- utils/
|   |-- __init__.py
|   |-- util_code1.py
|   |-- util_code2.py

I am trying to include utils package dir in setup.py of submodules.

here is how my setup.py looks

setup(
  name='sample_package',
  description='my test wheel',
  #packages=find_packages(),  
  packages=['main', '../../utils']
  entry_points={
    'group_1': 'module1=Example1.main.hello:method1'
  }
 ],
  include_package_data=True,
)

When I run command inside any of submodule python setup.py bdist_wheel to create a wheel for any submodule I am getting the following error.

error: package directory '../../utils' does not exist
sinoroc
  • 18,409
  • 2
  • 39
  • 70
Ramineni Ravi Teja
  • 3,568
  • 26
  • 37
  • From a first look, this will be a real pain... You will need to work with `package_dir`, and I am not even sure you will be able to create wheels. I think you should rather add another layer on top of your `setup.py` that would create the "correct" directory structure before running `setup.py`. -- Why is there a `__init__.py` next to each `setup.py`? – sinoroc Dec 04 '22 at 09:53
  • Basically, I think you will need something [like this](https://stackoverflow.com/a/69273346) or [this](https://stackoverflow.com/a/59662834). Where you would have a `package_dir` entry that looks like this: `'submoduleX.utils': '../utils'`, so that you can have in code `from submoduleX import utils`. -- But most likely, with the directory structure that you have, it will be impossible to create source distributions ("sdist") that work. – sinoroc Dec 04 '22 at 10:01
  • I want to create 3 wheel files separately for 3 submodules. So I have setup.py for each submodule. I want to access utils in wheel file of each submodule. – Ramineni Ravi Teja Dec 04 '22 at 15:03
  • 2
    I think it is possible, but you are really not setting up yourself for the easy path... If I were you I would put `utils` as an independent library with its own `setup.py` and use it as a dependency of the 3 others. -- If you do not want, then look at the links of my previous comment, it should be enough to put you on the right track. – sinoroc Dec 04 '22 at 17:52
  • 5
    "I am trying to access packages outside of the current package using setup.py" Then add the packages as a dependency. There's no need to reinvent the wheel (pun on purpose). – flakes Dec 04 '22 at 19:10

0 Answers0