pip installing data files to the wrong place

后端 未结 1 1643
失恋的感觉
失恋的感觉 2021-01-18 04:07

The source for the package is here

I\'m installing the package from the index via:

easy_install hackertray
pip install hackertray

<

相关标签:
1条回答
  • 2021-01-18 04:29

    Don't use data_files with relative paths. Actually, don't use data_files at all, unless you make sure the target paths are absolute ones properly generated in a cross-platform way insted of hard coded values.

    Use package_data instead:

    setup(
        # (...)
        package_data={
            "hackertray.data": [
                "hacker-tray.png",
            ],
        },
    )
    

    where hackertray.data is a proper python package (i.e. is a directory that contains a file named __init__.py) and hacker-tray.png is right next to __init__.py.

    Here's how it should look:

    .
    |-- hackertray
    |   |-- __init__.py
    |   `-- data
    |       |-- __init__.py
    |       `-- hacker-tray.png
    `-- setup.py
    

    You can get the full path to the image file using:

    from pkg_resources import resource_filename
    print os.path.abspath(resource_filename('hackertray.data', 'hacker-tray.png'))
    

    I hope that helps.

    PS: Python<2.7 seems to have a bug regarding packaging of the files listed in package_data. Always make sure to have a manifest file if you're using something older than Python 2.7 for packaging. See here for more info: https://groups.google.com/d/msg/python-virtualenv/v5KJ78LP9Mo/OiBqMcYVFYAJ

    0 讨论(0)
提交回复
热议问题