0

I have a library with the following structure:

├── mylib
│   ├── lib
│   │   └── __init__.py
│   ├── tools
│   │   └── __init__.py
│   ├── py_script
│   └── __init__.py

and I would like to do an editable pip install such that I can use mylib in other code like

from mylib.tools import useful_tool

and run py_script from the command line.

Is there a way to add a setup.py file to mylib that would allow for this import behavior without having to update the directory structure (e.g. moving everything into a new mylib/mylib folder)?

The reason for the constraint is that many people have been using mylib by manually adding the parent directory (e.g. mylib/...) to PYTHONPATH and PATH to get the import behavior above and I would prefer to not break that workflow.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
LexTron
  • 35
  • 1
  • 5
  • maybe see how to use `__all__` in this case – sahasrara62 Mar 01 '23 at 20:56
  • @sahasrara62 From looking at the [docs](https://docs.python.org/3/tutorial/modules.html#importing-from-a-package) on `__all__`, it seems it only restricts what gets imported when calling `import *` but it doesn't impact the syntax for importing from a project/package. – LexTron Mar 02 '23 at 01:02
  • Yep that's exactly what I was trying to find. Thank you! – LexTron Mar 02 '23 at 15:14

0 Answers0