Including data files with setup.py

假如想象 提交于 2019-12-10 15:27:04

问题


I'm having trouble including data files in my setup.py script. 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. To do so I used the package_data keyword in setuptools:

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:

recursive-include my_package/data_files *

setup.py seems to run fine and doesn't throw any errors. However, when I import the package I get a file not found error because my_data_file.csv is missing. 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?


回答1:


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)

In your case, the error is with your package_data line, the paths are relative to the namespace's root

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).



来源:https://stackoverflow.com/questions/45147837/including-data-files-with-setup-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!