Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Including Other Files in Your Python Package

In this lesson you’ll learn how to include other files in your Python package such as your config.txt defined in a previous lesson.

00:00 Occasionally, you’ll need to include other types of files in your package that aren’t source code. These may be CSV files, binaries, or config files, like we have in this project. When you run setup() it’s going to create something called a manifest file that’s going to include all source code and README files.

00:20 If all your project contains are source code and README files, you don’t need to modify the manifest at all. If you do have something else, like we have under reader/ a config.txt, you’re going to need to create a manifest template to include this.

00:38 So go to your top level directory, create a new file, and this needs to be called MANIFEST, in all caps, .in.

00:49 The only line you need to include in here is include reader/*.txt.

00:59 What this is going to do is it’s going to look in the reader/ folder and any .txt file that it sees, it’s going to include in the build.

01:07 Now, creating this file is fine. Then you need to make sure that if you go to setup.py, if you go down to this include_package_data, this must be set to True or it will ignore that file. All right!

01:21 And with that, you’ve finally done all the configuration and setup you need to get your work onto PyPI. Hopefully you’re starting to see that writing your actual code is only part of the effort, and there’s quite a bit of overhead that needs to be done to distribute your project. In the next video, you’ll actually build your package into a format that PyPI will accept, and then you’re ready for upload. Thanks for watching.

Lee Jordan on Oct. 25, 2020

Do we need to do this for subfolders that hold images and the image files inside them?

FooledByCode on Aug. 21, 2022

Nice course, I would really like to see this course updated with using toml and build

Geir Arne Hjelle RP Team on Aug. 21, 2022

@FooledByCode Thanks for your comment. We’ve updated the corresponding written tutorial to use pyproject.toml for configuration and build for building: realpython.com/pypi-publish-python-package/

Become a Member to join the conversation.