Python Packaging: Data files are put properly in tar.gz file but are not installed to virtual environment

前端 未结 5 1526
野趣味
野趣味 2020-12-07 20:24

I can\'t properly install the project package_fiddler to my virtual environment.

I have figured out that MANIFEST.in is responsib

相关标签:
5条回答
  • 2020-12-07 20:53

    The easiest way to include package data in "setup.py" is like so:

    package_data = {'<package name>': ['<path to data file within package dir>']}
    

    So in your example:

    package_data = {'package_fiddler': ['data/*', 'data/stylesheets/*']}
    

    package_data is a dictionary where the keys are the names of the packages included in the installer. The values under these keys should be lists of specific file paths or globs/wildcards within the package directory.

    You also need to include the flag:

    zip_safe=False
    

    in setup(...) if you want to be able to resolve file system paths to your data. Otherwise you can use pkg_resources to do this: http://peak.telecommunity.com/DevCenter/PythonEggs#accessing-package-resources

    You definitely don't need an __init__.py file in the "data" directory - this directory is not a module and is not meant to be imported.

    0 讨论(0)
  • 2020-12-07 20:56

    I personally dislike the way setuptools mixes code and data both conceptually and implementation-wise. I think that it's that implementation that is tripping you up here. For setuptools to find and use package_data it needs for the data to reside inside of a python package. A python package can be a directory but there needs to be a __init__.py file in the directory. So it looks like you need the following (empty is fine) files:

    ./package_fiddler/data/__init__.py
    ./package_fiddler/data/stylesheets/__init__.py
    
    0 讨论(0)
  • 2020-12-07 20:59

    Found a solution that worked for me here.

    Using setuptools==2.0.2 I did:

    setuptools.setup(
        ...
        packages=setuptools.find_packages(),
        include_package_data=True,  # use MANIFEST.in during install
        ...
    )
    
    0 讨论(0)
  • 2020-12-07 21:02

    This works for me. Hope it helps.

    package_data={
        "package_fiddler": [
            '\*.\*',
            '\*/\*.\*',
            '\*/\*/\*.\*',
        ],
    },
    
    0 讨论(0)
  • 2020-12-07 21:05

    use

    package_data={"data": ['package_fiddler/data',]}
    

    instead of

    packages=['package_fiddler',]
    
    0 讨论(0)
提交回复
热议问题