python alternative package setup using setuptools

旧城冷巷雨未停 提交于 2021-02-08 06:35:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!