Trying to learn how to run the following python script in frappe-bench directory.
import frappe
import json
from frappe.utils import flt
from frappe import _
import requests
from datetime import datetime, time
from frappe.utils import (
add_days,
cint,
create_batch,
cstr,
flt,
formatdate,
get_datetime,
get_number_format_info,
getdate,
now,
nowdate,
)
def my_function():
print("Hello, World!")
Tried to run the above script using the command below. The above script was saved in file named python_script.py
bench --site erpnext.domain.com execute python_script.my_function
Does not seem to work. Any advice?
Did I miss some steps?
1 Like
Hi @pvanthony !
You cannot execute scripts directly from “frappe-bench” directory itself. That directory is not a known path, for the Python virtual environment.
You’ll need to move your script into one of the Apps and Modules.
Real working example:
bench execute erpnext.get_default_company
3 Likes
Thank you for the advice. Very helpful.
From the erpnext telegram chat Devel Biene shared the following link.
Which was also helpful.
Here is what worked for me on erpnext 15.
bench --site erpnext.domain.com execute app_name.pvtest.my_function
Please note the following.
- the script file was placed in app_name/app_name
- file name is pvtest.py
- the function name in the file pvtest.py is called my_function.
So even if the script was in app_name/app_name, we only call it with one app_name instead of app_name.app_name.
1 Like