0

I have a file tree (look below) and my Python file api.py uses data from data/data.json. But I want to make sure that once I upload my package to PyPi it also includes the data directory, because if not the program just not gonna work at all.

- api
   __init__.py
   api.py
- data
    data.json
setup.py
README.md
requirements.txt
LICENSE
.gitignore

setup.py

from setuptools import setup, find_packages

with open('README.md', 'r') as f:
    long_description = f.read()
    
setup(
    name='api',
    version='1.0',
    author='name',
    author_email='email',
    description='api',
    long_description=long_description,
    long_description_content_type='text/markdown',
    url='link',
    packages=find_packages(),
    package_data={'api': ['../data/data.json']},
    include_package_data=True,
    install_requires=[
        'requests',
        'beautifulsoup4',
        'numpy',
      ]
)

How can I upload and include the data.json file?

Noa Kirel
  • 63
  • 6
  • 1
    Does this answer your question? [Including data files with setup.py](https://stackoverflow.com/questions/45147837/including-data-files-with-setup-py) – phd Jan 22 '21 at 08:17
  • https://stackoverflow.com/search?q=%5Bsetuptools%5D+include+data+file – phd Jan 22 '21 at 08:18
  • https://packaging.python.org/guides/distributing-packages-using-setuptools/#package-data, https://packaging.python.org/guides/using-manifest-in/ – phd Jan 22 '21 at 08:19
  • @phd Yeah but how do I use in my package python file? I downloaded my own package and the file that I included doesn't seem to exists. `No such file or directory: '../data/data.json'`. And it seems like that does not exists in`~/.local/lib/python3.8/site-packages/api` – Noa Kirel Jan 22 '21 at 10:52
  • It must be in `~/.local/lib/python3.8/site-packages/api/../data/data.json` i.e. `~/.local/lib/python3.8/site-packages/data/data.json`. – phd Jan 22 '21 at 13:01
  • @phd Then how do I put it there? `package_data` seems not to work, it does nothing, – Noa Kirel Jan 23 '21 at 08:22
  • When I said "It must be" I meant `pip install` must put it there based on `package_data={'api': ['../data/data.json']},` – phd Jan 23 '21 at 12:16

0 Answers0