bun_python
bun_python copied to clipboard
By default its not considering current working directory as source directory
create a file foo.py
and define a function
def greet(name: str):
return 'greet ' + name
then within js file
import { python } from "bun_python";
const foo = python.import('foo')
console.log(foo.greet('yourself'))
This will throw an error. I checked in sys.path, current working directory was not their. For now the only possible way to use this by a workaround like this
import { python } from "bun_python";
// +++++++manually add current working directory into sys path++++++
const sys = python.import('sys');
sys.path.append(__dirname);
const foo = python.import('foo')
console.log(foo.greet('yourself'))