[英]Including data files with setup.py
I'm having trouble including data files in my setup.py script. 我在setup.py脚本中包含数据文件时遇到问题。 My package is setup as follows:
我的包装设置如下:
my_package/
setup.py
MANIFEST.in
my_package/
__init__.py
access_data.py
data_files/
my_data_file.csv
I want to include the my_data_file.csv
file when installing so that it can be read by access_data.py
. 我想在安装时包含
my_data_file.csv
文件,以便access_data.py
可以读取access_data.py
。 To do so I used the package_data
keyword in setuptools
: 为此,我在
setuptools
使用了package_data
关键字:
setup(...,
packages=['my_package'],
package_data={'my_package': ['./my_package/data_files/my_data_file.csv']},
include_package_data=True
)
I also included the file in MANIFEST.in
: 我还在
MANIFEST.in
包含了该文件:
recursive-include my_package/data_files *
setup.py
seems to run fine and doesn't throw any errors. setup.py
似乎运行正常,不会抛出任何错误。 However, when I import the package I get a file not found error because my_data_file.csv
is missing. 但是,当我导入包时,我得到一个文件未找到错误,因为缺少
my_data_file.csv
。 I have tried referencing other stack overflow questions (particularly this one ) but can't figure out what I'm doing wrong. 我已经尝试引用其他堆栈溢出问题(特别是这一个 ),但无法弄清楚我做错了什么。 How can I get setup.py to include the necessary data files?
如何让setup.py包含必要的数据文件?
If it is listed in setup.py
's package_data
(correctly) you shouldn't need to include it in MANIFEST.in
(as it will be included automatically) 如果它在
setup.py
的package_data
(正确)中列出,则不需要将其包含在MANIFEST.in
(因为它将自动包含在内)
In your case, the error is with your package_data
line, the paths are relative to the namespace's root 在您的情况下,错误在于
package_data
行,路径相对于命名空间的根
In your case it should be: 在你的情况下,它应该是:
package_data={'my_package': ['data_files/my_data_file.csv']},
Also note that the key in package data is the dotted module path (it's not super relevant for this toy case however). 另请注意,包数据中的键是虚线模块路径(但这与此玩具案例并不相关)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.