4

On both Ubuntu 16.04 and Windows 7 (pip 18.1, python 2.7.15) , I am encountering an issue where I have package data that makes its way into the tar.gz file, but they do not get installed to my scripts directory when I install with pip. My scripts directory on windows is \Python27\Scripts. I also checked in site-packages and the file doesn't show up there. I want to have a textfile appear alongside the python scripts when installed via pip, and I think that using data_files does not achieve this (according to setup.py not installing data files ?

My package structure has all files (hello.py, MANIFEST.IN, setup.py)in the one root folder called fakeapp. I would like to keep this structure as the project that I actually am trying to fix has this structure.

I have looked up many answers and tried:

  • adding an empty __init__.py to the root of the repo and this didn't fix it.
  • I've tried adding and removing include_package_files=True to no avail
  • I've tried specifying package_data={'':['texto.txt']} as well as
    adding include texto.txt to MANIFEST.in to no avail.
  • This answer: suggests to use bdist, which also didn't work.

I'm sure that this is a duplicate question but I have not been able to get any solution to work.

So here's my test case: setup.py

from setuptools import setup
setup(
    author='hi',
    author_email='hi@hi.com',
    description="test",
    scripts=['hello.py',],
    license='MIT',
    name='hi',
    version='v2018.12.02',
    include_package_data=True
)

hello.py:

#!/usr/bin/env python

def main():
    print('hello world!')

if __name__ == '__main__':
    main()

MANIFEST.in:

include texto.txt

I created a tar.gz in dist/ with

python setup.py sdist

and my texto.txt is in that tarball.

and then i installed with

pip install dist\hi-2018.12.2.tar.gz

and only hello.py makes its way into C:\Python2.7\Scripts

What am I doing wrong?

Directory tree :

│   hello.py
│   MANIFEST.in
│   setup.py
│   texto.txt
│
├───dist
│       hi-2018.12.2.tar.gz
│
└───hi.egg-info
        dependency_links.txt
        PKG-INFO
        SOURCES.txt
        top_level.txt
Tandy Freeman
  • 528
  • 5
  • 15

1 Answers1

5

texto.txt is not actually package data, as it is not inside a package (a directory with an __init__.py), and thus it will not be installed. The simplest way to get what you want is to restructure your code so that it installs a package hello instead of a flat module hello.py, with hello.py being moved to hello/__init__.py and texto.txt being moved to hello/texto.txt.

jwodder
  • 54,758
  • 12
  • 108
  • 124
  • I'd mentioned in my post that I wanted to retain my directory structure, but your explanation makes sense - thanks! Is there definitely no way that I can get extra files to install via pip while keeping my flat structure? – Tandy Freeman Dec 25 '18 at 20:16
  • @TandyFreeman: The only way to do that would be with the `data_files` `setup()` argument, but the way that pip installs such files is so unfriendly that I recommend against ever using it. – jwodder Dec 25 '18 at 20:17
  • I might investigate that,looking at other answers it seems that data_files is a bit of a mess. But you've answered my question so I'll tick approved. – Tandy Freeman Dec 25 '18 at 20:20