【发布时间】:2019-10-14 12:56:04
【问题描述】:
我想设置一个 python 命名空间包,其中包含几个需要独立安装的连接包,除非明确指定依赖关系。然而,现有的解决方案对我来说似乎更多或更少混乱。
其中一个包包含大多数问题逻辑,例如,其他包包含辅助功能,例如绘图和数据导出。逻辑包需要保持苗条,并且不能导入超过numpy,因为其他包可以使用更复杂的包,如pandas 和matplolib。 我想设置一个看起来像命名空间包的结果命名空间的包结构,但没有不必要的文件夹嵌套类似 this:
namespace
├── logic
│ ├── __init__.py
| ├── functions.py
│ └── setup.py # requires numpy
├── datastructure
│ ├── __init__.py
| ├── functions.py
│ └── setup.py # requires namespace.logic and pandas
├── plotting
│ ├── __init__.py
| ├── functions.py
│ └── setup.py # requires namespace.logic, namespace.datastructure and matplotlib
└── setup.py #should install every package in namespace
我认为这看起来像一个带有模块的传统包,但我还没有找到将其设置为 packgae 的方法,而 mainintainign 选项只安装特定模块,因此我认为命名空间包应该提供该选项,但我不能完全让它与pip一起工作
目前我需要有两个这样的目录级别:
namespace
├── NamespaceLogic #don't want this
│ ├── namespace #don't want this
│ │ └── logic
│ │ └── __init__.py
│ └── setup.py
├── NamespaceDatastructure #don't want this
│ ├── namespace #don't want this
│ │ └── datastructure
│ │ └── __init__.py
│ └── setup.py
├── NamespacePlotting #don't want this
│ ├── namespace #don't want this
│ │ └── plotting
│ │ └── __init__.py
│ └── setup.py
└── setup.py
我的问题类似于这个问题:Python pip install sub-package from own package,但我想避免使用许多子文件夹,因为这会带来最大化我系统的路径长度限制的风险(+ 它会混淆其他人)。我需要如何配置不同的 setup.py 文件才能运行
pip install namespace #installs namespace.logic, namespace.datastructure, namespace.plotting
pip install namespce.logic #installs only namspace.logic and works in an environment with numpy which does not have pandas or matplotlib
【问题讨论】:
标签: python pip python-3.7 setup.py