如何在 python 中使用 pip install 安装软件包的地方添加 csv 文件?

how to add csv files where installing packages with pip install in python?

我花了很多时间来解决这个问题:

我的setup.py如下:

install_requires=install_requires,
python_requires='>=3.6.5',

include_package_data=True,

#### CLI
scripts = scripts,

但是,当 pip install -e . ,它不会将 *.csv、*.txt 文件复制到 MYpackages/ 中。 如何添加?

检查了以下资源:

Is it possible to include csv file as part of python package

https://python-packaging.readthedocs.io/en/latest/non-code-files.html

由于上面的链接没有提到,我们需要这一行 在 setup.py 中:

package_data={'': ['data/*.csv']},

并添加到MANIFEST.IN文件

recursive-include YourPackage/data/*.csv