Hi, trying out Prefect cloud, I have a Python scri...
# prefect-community
c
Hi, trying out Prefect cloud, I have a Python script that saves a png file using Matplotlib The method
plt.savefig
takes in a
file_path
arg (below is some sample code):
Copy code
CWD = os.path.dirname(os.path.abspath(__file__)) # Get CWD
file_path = os.path.join(CWD, "picture.png") # Save in CWD
plt.savefig(file_path)
This all works fine when I am running it on my server using
flow.run()
, however, when it is registered on cloud, invoking a Quick Run results in the error :
PermissionError: [Errno 13] Permission denied: '/picture.png'
The error shows that
file_path
is unable to be parsed to the current working directory that the script is being run from when triggered from Cloud. Would appreciate any insight.. if it helps, I am getting data from Google Sheets, plotting it and sending it to Slack, so I'd like to Prefect this workflow.
I found out the reason - CWD was called when inside a @task decorator. Calling CWD outside the scope of that task works, but can I understand why?
n
It sounds like when you're running your flow locally, you're doing so with elevated permission (maybe
sudo
or as a user with access to that file?) but perhaps your agent/executor don't have those same permissions?
c
This doesn't get parsed when called from Prefect cloud ( but gets parsed when run locally via
flow.run()
, from within
@task
):
Copy code
os.path.dirname(os.path.abspath(__file__))
So the path resolves to just
/'file_name'
. Writing to the root folder
/
is not allowed, hence
PermissionError: [Errno 13]
. The error is resolved when CWD gets called outside of
@task