IOError: [Errno 13] Permission denied u'data.csv'
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
IOError: [Errno 13] Permission denied u'data.csv'
Hello Lemma Soft Forums,
I'm currently working on a project and have run into a bit of a problem. The project is used as a means to collect data, which means that it needs to store said data in an external file for me to analyse. I have a script that works perfectly on windows, and does everything I want it to do. The problem arises when I try to make a mac-version of the game, where I get this error: IOError: [Errno 13] Permission denied u'data.csv'
I have tried various attempts at using sudo and chmod but those only give me syntax errors. My script looks as follows:
init python:
try:
prelude = open("data.csv","r")
except IOError:
prelude = open("data.csv","w+")
prelude.write("playerID" + "," + "playerName" + "," + "age" + "," + "gender" + "," +
"opponent" + "," + "choice" + "," + "opChoice" + "," + "condition" + "," + "day" + "," +
"security" + "," + "money" + "," + "food" + "," + "foodThief" + "," + "survivors" + "\n")
prelude.close()
This should create the file if it doesn't already exist. What can I do to possibly make this work on mac?
Thanks in advance,
Tobias
I'm currently working on a project and have run into a bit of a problem. The project is used as a means to collect data, which means that it needs to store said data in an external file for me to analyse. I have a script that works perfectly on windows, and does everything I want it to do. The problem arises when I try to make a mac-version of the game, where I get this error: IOError: [Errno 13] Permission denied u'data.csv'
I have tried various attempts at using sudo and chmod but those only give me syntax errors. My script looks as follows:
init python:
try:
prelude = open("data.csv","r")
except IOError:
prelude = open("data.csv","w+")
prelude.write("playerID" + "," + "playerName" + "," + "age" + "," + "gender" + "," +
"opponent" + "," + "choice" + "," + "opChoice" + "," + "condition" + "," + "day" + "," +
"security" + "," + "money" + "," + "food" + "," + "foodThief" + "," + "survivors" + "\n")
prelude.close()
This should create the file if it doesn't already exist. What can I do to possibly make this work on mac?
Thanks in advance,
Tobias
Re: IOError: [Errno 13] Permission denied u'data.csv'
1. Does the file already exist? If so, what are the file permissions on the ‘data.csv’ file on the Mac? Sounds like the file is either set to be “read only” or else is owned by a user different from the one that Ren’py is running under.
2. If the file doesn’t exist, does the user running the program have write permissions into the directory in which the app is trying to create the file?
2. If the file doesn’t exist, does the user running the program have write permissions into the directory in which the app is trying to create the file?
Re: IOError: [Errno 13] Permission denied u'data.csv'
The file does not already exist, it's trying to create it, so writing permission is most likely the problem. The question is how to give this permission? I unfortunately do not own a mac myself, so I cant properly troubleshoot. I've tried using sudo and chmod on my end, but those only give me syntax errors when used in renpy.
Re: IOError: [Errno 13] Permission denied u'data.csv'
So, I downloaded a Ren'py game onto my Mac, extracted it, and looked around. The structure of a Ren'py Mac app is as follows:
The "application" (as is true on all Mac apps) is actually a directory, ending in ".app". The Ren'py files (i.e. .rpa, .rpyc, etc) are located in
theAppName.app/Contents/Resources/autorun/game
All of the directories (the app and its subdirectories) extracted from the ZIP file I downloaded with permissions 755 (i.e. rwxr-xr-x) with my own user ID, which means that, in theory, if the app is running under my user ID, it should be able to write to those directories. That assumes, however, that the "current folder" for a Mac Ren'py app is the "game" folder - if it's not, your application could be trying to write into a place that you can't write without superuser permissions. You could probably figure that out by having some Python code that recorded the current working directory for the Ren'py app and displaying it on the user interface. That would be the first thing I'd experiment with.
In addition, it's possible that you're running afoul of some of the extra protection that recent versions of MacOS have put in place regarding modifications to applications - in the Ren'py app, all the resources are "inside" the application, unlike Windows in which there's an EXE and then external files.
So that's about all I can tell you right now. If I have an opportunity to experiment some more, I will.
The "application" (as is true on all Mac apps) is actually a directory, ending in ".app". The Ren'py files (i.e. .rpa, .rpyc, etc) are located in
theAppName.app/Contents/Resources/autorun/game
All of the directories (the app and its subdirectories) extracted from the ZIP file I downloaded with permissions 755 (i.e. rwxr-xr-x) with my own user ID, which means that, in theory, if the app is running under my user ID, it should be able to write to those directories. That assumes, however, that the "current folder" for a Mac Ren'py app is the "game" folder - if it's not, your application could be trying to write into a place that you can't write without superuser permissions. You could probably figure that out by having some Python code that recorded the current working directory for the Ren'py app and displaying it on the user interface. That would be the first thing I'd experiment with.
In addition, it's possible that you're running afoul of some of the extra protection that recent versions of MacOS have put in place regarding modifications to applications - in the Ren'py app, all the resources are "inside" the application, unlike Windows in which there's an EXE and then external files.
So that's about all I can tell you right now. If I have an opportunity to experiment some more, I will.
- PyTom
- Ren'Py Creator
- Posts: 15893
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: IOError: [Errno 13] Permission denied u'data.csv'
Writing files like this isn't supported in Ren'Py - Ren'Py does nothing to enforce the current working directory.
If you want to read the a file, renpy.file is what you want to use to get access it. You could plausibly use Python functions to find a writable location on the user's computer, but that's up to you to understand and implement.
If you want to read the a file, renpy.file is what you want to use to get access it. You could plausibly use Python functions to find a writable location on the user's computer, but that's up to you to understand and implement.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom
Re: IOError: [Errno 13] Permission denied u'data.csv'
OK, I have an answer - when a Ren'Py game is launched on the Mac (either through Ren'Py itself, or when built as an app and then run), the current working directory is '/' (i.e. the root of the file system)
That directory is owned by "root", not by the user currently running the application, and has permissions "drwxr-xr-x". Thus, non-root users aren't allowed to write into that directory, which completely explains the error that you're getting. (BTW, Linux will almost certainly have the same problem.)
To make this work on the Mac or Linux, you're going to have to use an explicit path to put the file somewhere that's writeable. And, of course, you're going to have to do that differently on each operating system.
Here's a block of code that might help:
This returns a string that represents a path to which to save the file:
- On Windows, it saves into the current working directory. I haven't verified where that is, but you presumably already know that
- On the Mac, it saves into the current user's "Documents" folder
- On Linux, it saves into the user's home directory
You can obviously adapt this bit of code to suit your needs.
Hope that helps...
That directory is owned by "root", not by the user currently running the application, and has permissions "drwxr-xr-x". Thus, non-root users aren't allowed to write into that directory, which completely explains the error that you're getting. (BTW, Linux will almost certainly have the same problem.)
To make this work on the Mac or Linux, you're going to have to use an explicit path to put the file somewhere that's writeable. And, of course, you're going to have to do that differently on each operating system.
Here's a block of code that might help:
Code: Select all
init python:
import os
def path_to_save_to():
if renpy.windows:
return "./data.csv"
if renpy.macintosh:
return os.path.join(os.path.expanduser('~'), "Documents", "data.csv")
if Ren'Py.linux:
return os.path.join(os.path.expanduser('~'), "data.csv")
return None
- On Windows, it saves into the current working directory. I haven't verified where that is, but you presumably already know that
- On the Mac, it saves into the current user's "Documents" folder
- On Linux, it saves into the user's home directory
You can obviously adapt this bit of code to suit your needs.
Hope that helps...
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], span4ev