Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing data files into site-packages with setup.py

I have a Python package with a standard setup.py installer but I cannot for the life of me get it to install some pre-defined configuration files into site-packages somewhere... my setup() function is called like this:

setup(
  name='Hydrant',
  version=version,
  description=long_description,
  author='Scott Frazer',
  author_email='[email protected]',
  packages=['hydrant'],
  package_data={'hydrant': ['sql/*.sql', 'hydrant.conf', 'hydrant.deploy']},
  data_files=[('config', ['hydrant/hydrant.conf'])],
  install_requires=[
    "xtermcolor>=1.0.3",
    "pyyaml",
    "pymysql",
    "jprops"
  ],
  entry_points={
    'console_scripts': [
      'hydrant = hydrant.Main:Cli'
    ]
  },
  test_suite='hydrant.test',
  license = "MIT",
)

I was experimenting around with package_data and data_files but they simply don't seem to DO anything. I'm installing into a virtual environment with the command line:

$ python setup.py install

Any insight would be greatly appreciated!

like image 791
Scott Frazer Avatar asked Mar 13 '12 18:03

Scott Frazer


People also ask

How do I add data to a Python package?

Place the files that you want to include in the package directory (in our case, the data has to reside in the roman/ directory). Add the field include_package_data=True in setup.py. Add the field package_data={'': [... patterns for files you want to include, relative to package dir...]} in setup.py .

How do I install Python packages from setup py?

Installing Python Packages with Setup.py To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

What is setup py in Python package?

The setup.py FileYour setup.py file is what describes your package, and tells setuptools how to package, build and install it. It is python code, so you can add anything custom you need to it. But in the simple case, it is essentially declarative. http://docs.python.org/3/distutils/

Can you have non-python files in a package?

For non-python files to be included in an installation, they must be within one of the installed package directories. If you specify non-python files outside of your package directories in MANIFEST.in, they will be included in your distribution, but they will not be installed.


1 Answers

Try adding a MANIFEST.in file to your module. Althought AFAIK it's only used to add data to generated packages (eggs or tar.gz distribution files)
Look at this StackOverflow related question/answer.

Others programmers made it work switching to distutils, but i wouldn't recommend it since it's deprecated by distribute.
Look at this other StackOverflow related question/answer

like image 155
KurzedMetal Avatar answered Sep 23 '22 15:09

KurzedMetal