File watcher under virtual environment
Answered
I have some file watchers that have to run under the project's virtual environment. How could I achieve that? I could not find it on the docs... :-)
Thanks in advance.
Please sign in to leave a comment.
Hi,
Sorry for a late reply.
Have you looked into https://www.jetbrains.com/help/pycharm/tutorial-file-watchers-in-product.html?
Could you please describe the usecase with more details?
I realise I am digging this up from the long-buried past, but hit the same issue and google steered me here.
My use case is a need to run a Django management command as a file watcher. Without the virtualenv, invoking manage.py fails. It would not be difficult to imagine other similar scenarios where a watcher needs to run a command within the current virtual env.
I can set the applicable environment variables VIRTUAL_ENV and PATH, obviously - but this is really a hacky solution that will not work on another system where different paths are used for the virtualenv etc. Currently, I have settled on using a manage.sh shell script that loads the virtual env using direnv and invoking the manage.py command, but this is just the lesser evil in available choices.
Being able to have Pycharm activate the virtual environment before executing the command would make sense in a Pycharm context.