How do I make setup.py include a file that isn’t part of the code? (Specifically, it’s a license file, but it could be any other thing.)
I want to be able to control the location of the file. In the original source folder, the file is in the root of the package. (i.e. on the same level as the topmost __init__.py.) I want it to stay exactly there when the package is installed, regardless of operating system. How do I do that?
Probably the best way to do this is to use the
setuptoolspackage_datadirective. This does mean usingsetuptools(ordistribute) instead ofdistutils, but this is a very seamless “upgrade”.Here’s a full (but untested) example:
Note the specific lines that are critical here:
package_datais adictof package names (empty = all packages) to a list of patterns (can include globs). For example, if you want to only specify files within your package, you can do that too:The solution here is definitely not to rename your non-
pyfiles with a.pyextension.See Ian Bicking’s presentation for more info.
UPDATE: Another [Better] Approach
Another approach that works well if you just want to control the contents of the source distribution (
sdist) and have files outside of the package (e.g. top-level directory) is to add aMANIFEST.infile. See the Python documentation for the format of this file.Since writing this response, I have found that using
MANIFEST.inis typically a less frustrating approach to just make sure your source distribution (tar.gz) has the files you need.For example, if you wanted to include the
requirements.txtfrom top-level, recursively include the top-level “data” directory:Nevertheless, in order for these files to be copied at install time to the package’s folder inside site-packages, you’ll need to supply
include_package_data=Trueto thesetup()function. See Adding Non-Code Files for more information.