add data files to python projects setup.py

前端 未结 3 533
被撕碎了的回忆
被撕碎了的回忆 2020-12-31 03:09

I have a project like this:

├── CHANGES.txt
├── LICENSE
├── MANIFEST.in
...
├── docs
│   └── index.rst
├── negar
│   ├── Negar.py
│   ├── Virastar.py
│   ├──         


        
相关标签:
3条回答
  • 2020-12-31 03:53

    Maybe try:

    package_data={'negar/data': ['data/*.dat']},
    
    0 讨论(0)
  • 2020-12-31 04:04

    I used data_files

    data_files = [('', ['negar/data/untouchable.dat'])],
    
    0 讨论(0)
  • 2020-12-31 04:08

    The first problem is that I didn't import my data file into the package with MANIFEST.in file. I imported it like this:

    include negar/data/*.dat
    

    After that my data file already imported with my package install. but because I had mistakes in open my data files, python couldn't find it. this question helped me to find the right way Python Access Data in Package Subdirectory and now I use something like this:

    import os
    this_dir, this_filename = os.path.split(__file__)
    DATA_PATH = os.path.join(this_dir, "data", "data.txt")
    print open(DATA_PATH).read()
    
    0 讨论(0)
提交回复
热议问题