Run command and Python virtual environments

256 views
Skip to first unread message

Benjamin Davidson

unread,
Feb 29, 2024, 5:22:00 PM2/29/24
to BBEdit Talk
I'm trying to use the #! : Run command with Python scripts but I'm unsure how to get the command to use the virtual environment that exists in the workspace folder. 

In the Python language settings, there is a an option to "Always use python when a virtual environment is active" which sounds like what I want but checking the box seems to have no effect. 

Any tips on how to make this work?

Thanks!

Benjamin Davidson

unread,
Mar 1, 2024, 9:33:21 AM3/1/24
to BBEdit Talk
[Update] I can make this work by including the path to my virtual environments python installation in the shebang line:

ie:

#!/Users/me/dev/bbedit_test/venv/bin/python

import requests
...

But this still leaves me wondering what the setting, "Always use python when a virtual environment is active" is supposed to do.

Thanks!

Rich Siegel

unread,
Mar 1, 2024, 9:45:47 AM3/1/24
to BBEdit Talk
On 1 Mar 2024, at 9:11, Benjamin Davidson wrote:

> [Update] I can make this work by including the path to my virtual
> environments python installation in the shebang line:
>
> ie:
>
> #!/Users/me/dev/bbedit_test/venv/bin/python
>
> import requests
> ...
>
> But this still leaves me wondering what the setting, "Always use python
> when a virtual environment is active" is supposed to do.

Ordinarily, when using "Run" from the #! menu, BBEdit will figure out whether to use `python` or `python3` to run Python scripts which don't have a !# line.

If "Always use “python” when a virtual environment is active" is turned on, *and* a Conda virtual environment is selected in the #! menu, then BBEdit will always run `python` and will not try to run `python3`.

Ordinarily, a #! line of "#!/usr/bin/env python" is enough, provided that your external Unix environment has $PATH set up correctly.

R.


--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <https://www.barebones.com/>

Someday I'll look back on all this and laugh... until they sedate me.
Reply all
Reply to author
Forward
0 new messages