Python virtual environments?

I am curious, what is the best way to run python in a virtual environment in a macro?

1 Like

I don't know about the "best", but the only way I know is
Execute a Shell Script using Python action

Hey @johns,

What virtual environment?

-Chris

For an example of some Python in a KM Execute Shell script action :

(if that is what you mean – the reference to a virtual environment is a bit gnomic, and needs unpacking)

1 Like

The main trick of using things like pipenv and virtualenv with Keyboard Maestro shell scripts is that you will have to explicitly export any shell variables that you need – the variables seen by Terminal.app etc are not automatically available to the new shell launched by an Execute Shell Script action

Thanks @ComplexPoint. I am indeed talking about python virtualenv. I found this interesting article on sourcing a virtual environment from with the python script, so I might give that a try.
https://www.a2hosting.com/kb/developer-corner/python/activating-a-python-virtual-environment-from-a-script-file

2 Likes
3 Likes

That's a good question. I only run my Python scripts from Anaconda virtual environments.
Given that I've just recently started using KM, I haven't tried executing Python scripts from a macro yet. This is going to get interesting.

1 Like