1

I am trying to add a configuration file to a python package. I want the configuration file to be placed in /etc/package-name/ but so far I was unable to do so.

The package structure is following, config.json is in the root directory and I am using python 2.7.12

├── config.json
├── installer
│   ├── child.py
│   ├── __init__.py
│   ├── install.py
├── MANIFEST.in
├── README.md
└── setup.py

I have tried few things. At first, I have added this line to setup.py which should ensure that the config.json is placed in the correct location.

setup(...,
data_files = [('/etc/beacons-node-installer/', ['config.json'])],
...)

But when it was not working I have added also package_dir and package_data variables:

setup(...,
package_dir={'installer': 'installer'},
package_data={'installer': ['config.json']},
data_files = [('/etc/beacons-node-installer/', ['config.json'])],
...)

After reading some python documentation I have noticed that version 2.7 changed few things and probably it is necessary to add file to MANIFEST.in so I tried this line

include config.json

Even this hasn't helped so now I am quite clueless. What is the correct way to install configuration file under /etc directory with pip?

Kostrahb
  • 709
  • 1
  • 9
  • 21
  • Possible duplicate of [setuptools sdist ignore data\_files](https://stackoverflow.com/questions/38117149/setuptools-sdist-ignore-data-files) – phd Dec 09 '17 at 12:59
  • 1
    Possible duplicate of [Copy configuration file on installation](https://stackoverflow.com/questions/47460804/copy-configuration-file-on-installation) – hoefling Dec 09 '17 at 14:56
  • See the answer to the question I linked. `pip install` will mistreat `data_files`, although you have defined them correctly! The only workaround to this is to avoid building wheels (i.e. use `sdist`) and prohibit building wheels from source tars on installation: `pip install mypkg --no-binary=mypkg`. – hoefling Dec 09 '17 at 15:03

0 Answers0