setup.py not installing data files

这一生的挚爱 提交于 2019-12-05 13:20:15

问题


I have a Python library that, in addition to regular Python modules, has some data files that need to go in /usr/local/lib/python2.7/dist-package/mylibrary.

Unfortunately, I have been unable to convince setup.py to actually install the data files there. Note that this behaviour is under install - not sdist.

Here is a slightly redacted version of setup.py

module_list = list_of_files

setup(name         ='Modules',
      version      ='1.33.7',
      description  ='My Sweet Module',
      author       ='PN',
      author_email ='email',
      url          ='url',
      packages     = ['my_module'],

# I tried this. It got installed in /usr/my_module. Not ok.

      # data_files   = [ ("my_module",  ["my_module/data1",
      #                                  "my_module/data2"])]

# This doesn't install it at all.
      package_data = {"my_module" : ["my_module/data1",
                                     "my_module/data2"] }
     )

This is in Python 2.7 (will have to run in 2.6 eventually), and will have to run on some Ubuntu between 10.04 and 12+. Developing it right now on 12.04.


回答1:


http://docs.python.org/distutils/setupscript.html#installing-additional-files

If directory is a relative path, it is interpreted relative to the installation prefix (Python’s sys.prefix for pure-Python packages, sys.exec_prefix for packages that contain extension modules).

This will probably do it:

data_files   = [ ("my_module",  ["local/lib/python2.7/dist-package/my_module/data1",
                                 "local/lib/python2.7/dist-package/my_module/data2"])]

Or just use join to add the prefix:

data_dir = os.path.join(sys.prefix, "local/lib/python2.7/dist-package/my_module")
data_files   = [ ("my_module",  [os.path.join(data_dir, "data1"),
                                 os.path.join(data_dir, "data2")])]



回答2:


UPD: package_data accepts dict in format {'package': ['list', 'of?', 'globs*']}, so to make it work, one should specify shell globs relative to package dir, not the file paths relative to the distribution root.

data_files has a different meaning, and, in general, one should avoid using this parameter.

With setuptools you only need include_package_data=True, but data files should be under version control system, known to setuptools (by default it recognizes only CVS and SVN, install setuptools-git or setuptools-hg if you use git or hg...)


with setuptools you can:

- in MANIFEST.im:

    include my_module/data*

- in setup.py:

    setup(
        ...
        include_package_data = True,
        ...
    )


来源:https://stackoverflow.com/questions/11235820/setup-py-not-installing-data-files

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