gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:26:18 26 4
gpt4 key购买 nike

我有这样一个项目:

├── 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")

最佳答案

我用了data_files

data_files = [('', ['negar/data/untouchable.dat'])],

关于python - 将数据文件添加到python项目setup.py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12191339/

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