Hello,
What’s the best way to run a Python job that activates a virtualenv before it runs?
How are you submitting? Python API, Command line, Monitor or Integrated submitter?
You can do a PreJob script or an OnJobSubmitted event. Depends if you want this for every job, only specific jobs or copying the submitter’s environment.
We have some examples of setting environment variables…
Copy Submitter’s Env:
github.com/ThinkboxSoftware/Dea … entCopy.py
Set Plugin Env:
github.com/ThinkboxSoftware/Dea … PreLoad.py
Regards,
Charles
I’m submitting using deadlinecommand with a job and plugin file. I’m using the Deadline Python plugin. I was hoping to have the virtualenv be an option, so that I could choose to activate it if I wanted. So if it is enabled, it would call the activate.bat file in the virtualenv specified before executing the Python script. The goal is not to provide a list of environment variables, but rather have virtualenv activate before running Python in the same process.
I just got a crash course in virtual environments from one of our experts here. It looks like “activate(.bat)” needs to be called, then in the same environment we need to call a second command. While it might work to run in the pre-job script (I believe it runs in the same sandbox), it will probably be a better plan to throw everything into a batch or shell script and run it through the command line plugin.
Since virtualenvs are really starting to take off though, what would you want to see in the Python plugin to add better support for them? I’ve only seen the benefit on the developer side here. Can they be ported over for deployments and cleaned up again? I can’t imagine adding some extra sugar to the Pre and Post job functions in the plugin (assuming they’ll work) will be very difficult on a development angle.
Putting it all in a batch script seems like a good way to go. If Deadline were to add support for virtualenv in the Python plugin, it would be great to be able to choose which virtualenv to activate before running the Python script. I’m not sure what you mean by porting over for deployments then cleaning up.
Thank you for your response.