How to run a python script in frappe-bench directory?

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?

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

1 Like