commandvirtualenvoctavemozilla-deepspeech

Want to activate a virtual environment from terminal with Octave/Matlab


I would like to execute a bash command to activate a virtual environment with Octave using Linux. What I actually want to do is run DeepSpeech using Octave/Matlab.

The command I want to use is source $HOME/tmp/deepspeech-venv/bin/activate

The line of code I tried on my own is system("source $HOME/tmp/deepspeech-venv/bin/activate")

And the output I'm getting is sh: 1: source: not found

I saw this answer on a post and tried this command setenv('PATH', ['/source $HOME/tmp/deepspeech-venv/bin/activate', pathsep, getenv('PATH')]) but with no help it returned the same error.


Solution

  • It's not completely clear from your question, but I'm assuming you're trying to do is run python commands within octave/matlab, and you'd like to use a python virtual environment for that.

    Unfortunately, when you run a system command from within octave, what most likely happens is that this creates a subshell to execute your command, which is discarded once the command has finished.

    You have several options to rectify this, but I think the easiest one would be to activate the python virtual environment first, and run your octave instance from within that environment. This then inherits all environmental variables as they existed when octave was run. You can confirm this by doing getenv( 'VIRTUAL_ENV' ).

    If that's not an option, then you could make sure that all system commands intended to run python scripts, are prefixed with a call to the virtual environment first (e.g. something like system( 'source ./my/venv/activate; python3 ./myscript.py') ).

    Alternatively, you can try to recreate the virtual environment from its exported variables manually, using the setenv command.