Packaging resources with setuptools/distribute

前端 未结 1 1456
[愿得一人]
[愿得一人] 2020-12-08 23:41

I\'m developing an Python egg that has several .txt dependencies (they\'re templates used to generate files by the egg itself), and I\'m struggling to get those dependencies

相关标签:
1条回答
  • 2020-12-09 00:12

    Have you looked at the setuptools documentation for including package data here: https://setuptools.readthedocs.io/en/latest/setuptools.html#including-data-files

    Basically, you just need to set include_package_data=True in your setup.py file. If you are using subversion or CVS, all versioned files will be included. If not, you can specify which files to include with a MANIFEST.in file.

    I believe distribute supports this as well.

    You can then access the files as you would without them being packaged. i.e. in main.py you could have:

    import os.path
    f = open(os.path.join(os.path.dirname(__file__),'templates','file1.txt'))
    print f.read()
    f.close()
    

    and this would work in the packaged version as well. One caveat is that you will have to also set zip_safe = False in setup.py so that all the files are unzipped during installation.

    0 讨论(0)
提交回复
热议问题