Python 3.x Setuptools-查找包和自动子模块依赖关系管理

Python 3.x Setuptools-查找包和自动子模块依赖关系管理,python-3.x,setuptools,dependency-management,Python 3.x,Setuptools,Dependency Management,我正在尝试用python为自己设置一些小的ish支持库和项目。我打算将其模块化,并将其作为git子模块进行管理,以便导入到其他git回购中。那部分很好用 我不能很好地管理python中那些子模块的依赖性。我正试图让setuptools.find_package()实现这一点,但我似乎无法理解 我相信这有点像我所期待的,但它的措辞如此之高,以至于我似乎无法得到正确的实现 我的目标: 我不想在父模块的requirements.txt或setup.py中明确列出子模块的依赖项。我用这种方式“工作”。

我正在尝试用python为自己设置一些小的ish支持库和项目。我打算将其模块化,并将其作为git子模块进行管理,以便导入到其他git回购中。那部分很好用

我不能很好地管理python中那些子模块的依赖性。我正试图让setuptools.find_package()实现这一点,但我似乎无法理解

我相信这有点像我所期待的,但它的措辞如此之高,以至于我似乎无法得到正确的实现

我的目标:

  • 我不想在父模块的requirements.txt或setup.py中明确列出子模块的依赖项。我用这种方式“工作”。但最终在更大的项目上,这不是一条可行的道路,所以我想从一开始就做好事情
  • 对于作为独立项目的子模块,以及在其他项目中使用子模块时,该结构应该是有意义的。我不介意结构是否与下面的不同。我只是希望仍然能够自己使用子模块
以下是我所拥有的:

MyProj
├── MyProj
│   ├── __init__.py
│   ├── main.py
│   └── submodule
│       ├── setup.py
│       └── submodule
│           ├── hello.py
│           └── __init__.py
└── setup.py
MyProj.setup.py:

from setuptools import setup, find_packages

""" a minimalist setup.py sample structure """

setup(
   name='MyProj',
   version='0.1.0',
   author='An Awesome demo of the basics of using pkgs',
   author_email='blablabla.it@gmail.com',
   packages=find_packages(),
   description='An awesome package that does something',
   install_requires=["PyYAML"],
)
子模块.setup.py

from setuptools import setup, find_packages

""" a minimalist setup.py sample structure """

setup(
   name='submodule',
   version='0.1.0',
   author='An Awesome demo of the basics of using pkgs',
   author_email='blababla.it@gmail.com',
   packages=find_packages(),
   license='license.txt',
   description='An awesome package that does something',
   install_requires=["numpy"],
)
MyProj.main:

from MyProj.submodule.submodule.hello import count_matrix

if __name__ == '__main__':
    print(count_matrix())
hello.py
只需使用numpy构建一个矩阵(以检查即使在其他地方导入时子模块的依赖关系是否得到正确管理),然后MyProj.main只需调用
hello.py

如果我跑步:

pip install .
从/MyProj开始,MyProj将安装fine及其PyYaml依赖项:

Successfully built MyProj
Installing collected packages: PyYAML, MyProj
  Attempting uninstall: MyProj
    Found existing installation: MyProj 0.1.0
    Uninstalling MyProj-0.1.0:
      Successfully uninstalled MyProj-0.1.0
Successfully installed MyProj-0.1.0 PyYAML-5.3.1
但是,如果我运行MyProj.main,那么
ModuleNotFoundError:没有名为'numpy'的模块
,并且我可以从以前的pip安装中看出没有安装numpy。子模块也不适用于该问题