#$`source .venv/bin/activate` can't be executed
1 messages · Page 1 of 1 (latest)
I think you should run source .venv/bin/activate and then your bun script from that shell.
Although, reading the activate script created by venv, it only prepends the PATH, so you could do something like this:
import { $ } from "bun";
$.env({ PATH: process.env.PWD + "/.venv/bin:" + process.env.PATH });
console.log(await $`which python`.text());
That should give you the python from your venv. The activate script also deals with portability with windows and setting the prompt, but I don't think those are issues if you are running it from bun.
You might also want to unset the PYTHONHOME var if you have it set for some reason (I can't see a way to do this with $ but process.env works:
delete process.env.PYTHONHOME;
Thanks a lot! Does it mean bun can't run a shell script within TypeScript? Like $`./script.sh`
I think you should be able to. Maybe you'll need to run it as $`bash ./script.sh` instead.
I see, but it launches a child process, doesn't it? Is it impossible to run scripts in the same process?