Search code examples
pythonpackagesetuptoolsdistutils

What is the minimal usage for including data in a python 3 package build using distutils setup()?


I am trying to build my first package in python 3.6.3. I've read through the docs and searched the questions, but can't seem to understand what I'm doing wrong.

My package directory structure is as follows:

| - mypkg/
|   | - setup.py 
|   | - someModule/
|   |   | - __init__.py
|   |   | - a.py
|   |   | - b.py
|   |   | - data /
|   |   |   |- somedata.xml

My setup script is:

#!/usr/bin/env python

from distutils.core import setup

setup(...
      packages=['someModule'],
      data_files = [('someModule', ['someModule/data/somedata.xml'])]
      )

However when I run python setup.py build my data is not being added to the build/lib/mypkg directory. What am I doing wrong?


Solution

  • I solved the problem. In the end using the package_data argument instead of the data_files argument did it, i.e. I changed setup.py to:

    setup(...
          packages = ['someModule'],
          package_data = {'someModule': ['data/somedata.xml']},
          )
    

    Thanks to @Martijn Pieters for the tip that data_files is for data that lives outside the package.