add data files to python projects setup.py

前端 未结 3 536
被撕碎了的回忆
被撕碎了的回忆 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 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()
    

提交回复
热议问题