I want to build html docs using a virtualenv instead of the native environment on my machine.
I’ve entered the virtualenv but when I run make html I get errors saying the module can’t be imported – I know the errors are due to the module being unavailable in my native environment.
How can I specify which environment should be used when searching for docs (eg the virtualenv)?
The problem here is that
make htmluses thesphinx-buildcommand as a normal shell command, which explicitly specifies which Python interpreter to use in the first line of the file (ie.#!/usr/bin/python). If Python gets invoked in this way, it will not use your virtual environment.A quick and dirty way around this is by explicitly calling the
sphinx-buildPython script from an interpreter. In theMakefile, this can be achieved by changingSPHINXBUILDto the following:If you do not want to modify your
Makefileyou can also pass this parameter from the command line, as follows:Now if you execute
make buildfrom within your VirtualEnv environment, it should use the Python interpreter from within your environment and you should see Sphinx finding all the goodies it requires.I am well aware that this is not a neat solution, as a
Makefilelike this should not assume any specific location for thesphinx-buildfile, so any suggestions for a more suitable solution are warmly welcomed.