安装模块内的 Setup.py [英] Setup.py inside installed module
问题描述
对于像下面这样的目录结构,我无法使 xy
成为可导入的包.
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
如果 setup.py
是一个目录,我可以使用
If the setup.py
were a directory up, I could use
from setuptools import setup
setup(name='xy',
packages=['xy'])
但除此之外,没有package_dir
和packages
的组合让我import xy
,只有import z
.不幸的是,移动 setup.py 目录并不是一个真正的选择由于过多的硬编码路径.
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.
推荐答案
有关如何使用 package_dir
和 packages
来帮助此类项目的想法,请参阅以下答案:https://stackoverflow.com/a/58429242/11138259
See the following answer for ideas how to use package_dir
and packages
to help with such projects: https://stackoverflow.com/a/58429242/11138259
简而言之:
#!/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': '.',
},
)
这篇关于安装模块内的 Setup.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!