Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I distribute data files with a python package such that they're readable?

I have a python module with a setup like this:

from distutils.core import setup
setup = (
    ...
    package_data={'mypackage': ['my/file.data']})

in a package laid out like this:

mypackage/
    setup.py
    mypackage/
        __init__.py
        my/
            file.data

and __init__.py looks something like this:

import pkgutil
DATA = pkgutil.get_data(__name__, 'my/file.data')

Pretty simple. All I want is to get some data into my python plugin. However, when I install it with

sudo python setup.py install

and try to run it, I get

IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/mypackage/my/file.data'

It's been installed with incorrect permissions.

How do I distribute data and config files in python such that they can be read at runtime?

like image 976
So8res Avatar asked May 23 '26 03:05

So8res


1 Answers

I’m afraid you can’t do that out of the box: if I recall correctly file permissions are just copied as is. You’d need to write a custom build command to change the file rights in the build directory before they are copied by the install command.

The simplest solution would be to have the desired rights in your repository or source tree.

like image 71
merwok Avatar answered May 24 '26 17:05

merwok