Search code examples
pythonmodulepippypi

How to include txt file within pip(pypi) module


I created an pip module and installed the module in jupyter notebook.

There is one function that is not working because of the following.

I created a pip module and within this module I also have one text file with some information that is needed for the toolbox.

But when I create the pypi module, this txt file is not converted into the python wheel and now after installing this txt file cannot be found.

Is there a way to include a txt file within this module, or do I need to convert this txt file into another format (.csv?).


Solution

  • You're probably calling setuptools.setup in your setup.py file to package your code. The logic by which setup decides which files to include in the wheel is, while it mostly works out of the box, a little complicated.

    In your case, it should be enough to add the file path of your .csv to a package_data-list:

    from setuptools import setup
    
    setup(
        ...                                      # "name" and stuff
        packages=['mypkg'],                      # root folder of your package
        package_dir={'mypkg': 'src/mypkg'},      # directory which contains the python code
        package_data={'mypkg': ['data/*.csv']},  # directory which contains your csvs
    )
    

    Concerning the use MANIFEST, not package_data argument the doc pages talk about, since you use wheel to build the package you should be fine. wheel uses bdist by default, which works well with package_data.