问题
I am having some trouble adding packages with my particular setup:
.
├── pkg_a
│ ├── pkg_a
│ │ ├── __init__.py
│ │ └── module_a.py
│ └── run_a.py
├── pkg_b
│ ├── pkg_b
│ │ ├── __init__.py
│ │ └── module_b.py
│ └── run_b.py
└── setup.py
My goal is to be able to import package modules without repeating package name twice.
For example, in run_a.py
I'd like to be able to call from pkg_a import module_a
instead of calling from pkg_a.pkg_a import module_a
I tried to follow Section 2.1 of doc here. By creating setup.py
as follow:
from setuptools import setup
setup(
name="test",
packages=['pkg_a', 'pkg_b'],
package_dir={'pkg_a':'pkg_a/pkg_a', 'pkg_b':'pkg_b/pkg_b'}
)
But this does not achieve the desired effect as mentioned above as I tried to call python setup.py develop
and then python -c 'from pkg_a import module_a'
.
Is this particular setup achievable? And what am I messing up here? Thanks all!
回答1:
package_dir
modifications do not work with editable (aka develop) installations. The only acceptable package_dir
modification for editable installations is the one that covers the so-called src
-layout:
package_dir={'': 'src'},
来源:https://stackoverflow.com/questions/65591066/python-alternative-package-setup-using-setuptools