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?
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.
I also have this problem and I solve it.
As @Éric Araujo said, you should change the pemission of your file.data
. If the permission of your file is 400
, it will be also installed with permission 400
. But the owner will be root
if you installed the package using root
permission. And this can't be read by normal users.
I think it will be enough to change the permission to 644
. And remember to delete mypackage.pkg-info
, build
and dist
in your currnet location, or you can't apply the new permission of your data file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.