你可以试试
packages=['package1', 'package2', 'package3'],
package_dir={
'package2': 'package1',
'package3': 'package1',
},
告诉 distutils 包 2 和 3 位于 package1 中。
完整的 setup.py 可能如下所示:
#!/usr/bin/env python
from distutils.core import setup
setup(name='root',
version='1.0',
description='Root package',
author='Me',
author_email='me@example.org',
url='https://example.org/root',
packages=['package1', 'package2', 'package3'],
package_dir={
'package2': 'package1',
'package3': 'package1',
},
)
python -m pip install ./root
将包安装到您要查找的结构中,这样
import package1
import package2
import package3
工作。
作为证明,这就是ls package*
site-packages 目录中的样子:
package1:
__init__.py __pycache__
package2:
__init__.py __pycache__
package3:
__init__.py __pycache__
这是root-1.0.dist-info/RECORD
文件:
package1/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
package1/__pycache__/__init__.cpython-37.pyc,,
package2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
package2/__pycache__/__init__.cpython-37.pyc,,
package3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
package3/__pycache__/__init__.cpython-37.pyc,,
root-1.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
root-1.0.dist-info/METADATA,sha256=Z1crlNNrRhJwO6O2ujtNsCo9rURrPoZGE0--ZhuBZsU,190
root-1.0.dist-info/RECORD,,
root-1.0.dist-info/WHEEL,sha256=g4nMs7d-Xl9-xC9XovUrsDHGXt-FT0E17Yqo92DEfvY,92
root-1.0.dist-info/top_level.txt,sha256=svjaZCiNfClr21KxGb71MTR7bWON1-VZRPiPgM0FjV4,27