将数据文件添加到python项目setup.py

2024-02-02

我有一个这样的项目:

├── CHANGES.txt
├── LICENSE
├── MANIFEST.in
...
├── docs
│   └── index.rst
├── negar
│   ├── Negar.py
│   ├── Virastar.py
│   ├── Virastar.pyc
│   ├── __init__.py
│   ├── data
│   │   ├── __init__.py
│   │   └── untouchable.dat
│   ├── gui.py
│   ├── gui.pyc
│   ├── i18n
│   │   ├── fa_IR.qm
│   │   └── fa_IR.ts
│   └── negar.pro
├── setup.py
...

里面是我的文件Virastar.py需要一些数据data.untouchable.dat。它工作正常,直到我用这个安装项目setup.py:

setup(
    ...
    include_package_data=True,
    packages = find_packages() + ['negar'],
    package_dir={'negar': 'negar'},
    package_data={'negar': ['data/*.dat']},
    entry_points={
        'console_scripts': [
            'negar = negar.Negar:main',
        ],
    }, 
    ...  
)

之后,当我启动程序并且需要该数据文件时,它会返回以下错误:

IOError: [Errno 2] No such file or directory: 'data/untochable.dat'

即使在我的egg-info来源我找不到任何数据文件:

...
negar/Negar.py
negar/Virastar.py
negar/__init__.py
negar/gui.py
negar/data/__init__.py

我在这里错过了什么吗?

谢谢你们。

编辑:我是否需要添加任何特殊的东西init.py?

我必须补充一点:我使用了 untouchable.dat 就像这样:

f = codecs.open('data/untouchable.dat', encoding="utf-8")

I used 数据文件 http://docs.python.org/2/distutils/setupscript.html#distutils-additional-files

data_files = [('', ['negar/data/untouchable.dat'])],
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将数据文件添加到python项目setup.py 的相关文章

随机推荐