Try ERPNext Buy Support Partners Foundation

Run some custom script (ImportError: No module named frappe)

Guys, I am newcomer in erpnext.
Could you please explain me why I can’t run python script with frappe as ussual.

For example I try to run tests:

frappe@erpnext:~/frappe-bench/apps/frappe/frappe$ python test_runner.py
Traceback (most recent call last):
File “test_runner.py”, line 6, in
import frappe
ImportError: No module named frappe

but if I run bench run-tests it works

I can’t understand import frappe magic configuration)
I just want create my custom script and run it.

For example my script:

import frappe

if name == "__main__":
    frappe.connect()
    frappe.clear_cache()
    frappe.db.sql("select name from tabCompany")

How to run it and resolve error:
ImportError: No module named frappe ?

Could you help me please or give some example :disappointed:

Hi, you can run specific functions by using the bench execute command. For eg

# in file test.py inside frappe/frappe/ folder
def test():
    print "hello!"

bench execute frappe.test.test will give the output “hello!”

That same function can also run from a bench console like so

frappe@ubuntu:~/frappe-bench$ bench console

In [1]: from frappe.test import test

In [2]: test()
hello!

In [3]: