Drush contrib modules not available if executed externally Using Drush 5.8 contrib modules are not available if executed externally.

E.g. Drush Entity is not available if executed on a Django view via a check_output:

check_output("drush -l example.com -r /var/www/my/example/site/ entity-read node", shell=True)


Any command regarding Drush Entity return an error specifying that the command "could not be found.  Run drush cache-clear drush to clear the commandfile cache if you have installed new extensions."

The same command is available if executed via an interactive python shell or via ssh.

I've installed Drush Entity in this way:

drush dl drush_entity


This command on my system put drush_entity into /home/admin/.drush directory. This directory seems to be ignored, since site-alias too are ignored if i put them inside that directory.
The solution is to pass the environment variable $HOME to check_output, in this case /home/admin:

check_output("drush -l example.com -r /var/www/my/example/site/ entity-read node", shell=True, env={'HOME': "/home/admin"})


This force the /home/admin/.drush directory to be read. If everything is fine this command:

drush ev 'print(drush_server_home());'


should return /home/admin. If drush_server_home() returns an empty string, contrib modules installed inside .drush on home directory will not be available.

Ensure to install contrib modules with the same user controlling the /home/admin directory.

Read the documentation of the language you're using to pass the $HOME variable on command execution.