gpt4 book ai didi

python - 为什么 setuptools 不复制子文件夹中的模块?

转载 作者:太空狗 更新时间:2023-10-30 02:30:01 24 4
gpt4 key购买 nike

我有一个名为 hwrt 的项目(参见 GitHubPyPI),其结构如下:

.
├── bin
├── docs
├── hwrt
│   ├── datasets
│   │   ├── crohme_eval.py
│   │   ├── __init__.py
│   │   ├── inkml.py
│   │   ├── README.md
│   │   └── results.csv
│   ├── __init__.py
│   ├── misc: Not important for this question
│   ├── selfcheck.py
│   ├── serve.py
│   ├── ... (more Python modules)
│   ├── templates: Not important for this question
│   └── view.py
├── LICENSE
├── Makefile
├── MANIFEST.in
├── README.md
├── requirements.txt
├── setup.cfg
├── setup.py
└── tests: Not important for this question

我的问题是

$ python
>>> from hwrt.datasets import inkml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named datasets

root/of/project$ python
>>> from hwrt.datasets import inkml
>>>

请注意,datasets 文件夹中有 __init__.py。所以这不是问题。一个(那个?)问题似乎是 setuptools 不复制数据集文件夹。除了将 __init__.py 放入文件夹之外,我还需要做任何其他事情吗?

设置.py
try:
from setuptools import setup
except ImportError:
from distutils.core import setup

config = {
'name': 'hwrt',
'version': '0.1.217',
'author': 'Martin Thoma',
'author_email': 'info@martin-thoma.de',
'maintainer': 'Martin Thoma',
'maintainer_email': 'info@martin-thoma.de',
'packages': ['hwrt'],
'scripts': ['bin/hwrt', 'bin/backup.py',
'bin/test.py', 'bin/train.py',
'bin/create_testset_online_once.py'],
'package_data': {'hwrt': ['templates/*', 'misc/*']},
'platforms': ['Linux', 'MacOS X', 'Windows'],
'url': 'https://github.com/MartinThoma/hwrt',
'license': 'MIT',
'description': 'Handwriting Recognition Tools',
'long_description': ("A tookit for handwriting recognition. It was "
"developed as part of the bachelors thesis of "
"Martin Thoma."),
'install_requires': [
"argparse",
"theano",
"nose",
"natsort",
"PyYAML",
"matplotlib",
"nntoolkit",
"h5py",
"flask",
"flask-bootstrap",
"requests",
"six"
],
'keywords': ['HWRT', 'recognition', 'handwriting', 'on-line'],
'download_url': 'https://github.com/MartinThoma/hwrt',
'classifiers': ['Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Software Development',
'Topic :: Utilities'],
'zip_safe': False,
'test_suite': 'nose.collector'
}

setup(**config)

最佳答案

默认情况下,setup() 中的“packages”关键字不包括所有子包。它只查找包含在与 setup.py 相同的文件夹中的包。您只需将“hwrt.datasets”添加到您的包列表即可。

但是,如果您决定向项目中添加更多包,那么以后可能会遇到麻烦,因此典型的用例是使用辅助函数 find_packages。

例如:

from setuptools import setup, find_packages

setup(
# ...
packages=find_packages(".")
)

参见 http://setuptools.readthedocs.io/en/latest/setuptools.html#using-find-packages

关于python - 为什么 setuptools 不复制子文件夹中的模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29609141/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com