title: Cannot activate Conda environment from subprocess
body: <p>I am building an <code>Electron</code> app (running an Angular application) which acts as the User Interface for a <code>python</code> program underneath.</p>
  
  <p>The <code>python</code> program uses <code>anaconda</code> for package management (I am using <code>miniconda</code> for development).</p>
  
  <p>When the app boots up, it checks whether the required <code>conda</code> environment exists, and if not, <strong>creates</strong> it.</p>
  
  <p>The following code is part of a <code>Service</code> which is responsible for managing the <code>python</code> program.</p>
  
  <pre><code>public doEnvironmentSetup() {
      let stdOutSub = new Subject&lt;string&gt;();
      let stdErrSub = new Subject&lt;string&gt;();
      let completeSubject = new Subject&lt;string&gt;();
      this.runningSetup = true;
  
      const TEMP_ENV_FILE = join(tmpdir(), "env.yml");
  
      return Promise.resolve()
        .then(() =&gt; {
  
          // Copy packaged environment.yml to TEMP_ENV_FILE
  
        })
        .then(() =&gt; this.electron.getApplicationStoragePath())
        .then((stor) =&gt; {
  
          setTimeout(() =&gt; {
  
            let runProcess = this.electron.childProcess.spawn("conda", ["env", "create", "--file", TEMP_ENV_FILE, "--name", CONDA_ENV_NAME], {
              cwd: stor
            });
  
            const stdOutReaderInterface = createInterface(runProcess.stdout);
            const stdErrReaderInterface = createInterface(runProcess.stderr);
  
            stdOutReaderInterface.on('line', (line) =&gt; {
              stdOutSub.next(line);
            });
  
            stdErrReaderInterface.on('line', (line) =&gt; {
              stdErrSub.next(line);
            });
  
            runProcess.on('close', (code: number) =&gt; {
              this.electron.fs.unlinkSync(TEMP_ENV_FILE);
              this.runningSetup = false;
              completeSubject.next("");
            });
  
          }, 2000);
  
          return {
            stdOut: stdOutSub,
            stdErr: stdErrSub,
            onComplete: completeSubject
          };
  
        });
  
    }
  </code></pre>
  
  <p>Now, when I need to run the actual <code>python</code> code, the piece of code which runs is (not giving the whole thing, since it is too long for our purpose here) :</p>
  
  <pre><code>        execCmd.push(
            `conda init ${this.electron.os.platform() === "win32" ? "powershell" : "bash"}`,
            `conda activate ${CONDA_ENV_NAME}`,
            // long python spawn command
            `conda deactivate`,
          )
  
          setTimeout(() =&gt; {
  
            logLineSubject.next({ out: "--- Setting up Execution Environment ---", err: "" });
  
            logLineSubject.next({ out: `Running in ${dir}`, err: "" });
  
            const cmd = execCmd.join(" &amp;&amp; ");
  
            let runProcess = this.electron.childProcess.spawn(cmd, {
              detached: false,
              windowsHide: true,
              cwd: cwd,
              shell: this.getShell()
            });
  
            const stdOutInterface = createInterface(runProcess.stdout);
            const stdErrInterface = createInterface(runProcess.stderr);
  
            stdOutInterface.on('line', (line) =&gt; {
              // get this line back to the component
            });
  
            stdErrInterface.on('line', (line) =&gt; {
              // get this line back to the component
            });
  
            runProcess.on("error", (err) =&gt; {
              // get this back to the component
            });
  
            runProcess.on('close', (code: number) =&gt; {
              // get this line back to the component
            });
  
          }, 1000);
  </code></pre>
  
  <p>where <code>getShell</code> is defined as:</p>
  
  <pre><code>private getShell() {
    return process.env[this.electron.os.platform() === "win32" ? "COMSPEC" : "SHELL"];
  }
  
  </code></pre>
  
  <p>However, whenever I try to run this, it comes back with:</p>
  
  <pre><code>CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
  To initialize your shell, run
      $ conda init &lt;SHELL_NAME&gt;
  blah blah blah ...
  </code></pre>
  
  <p>When I try with <code>source activate ${CONDA_ENV_NAME}</code>, it comes back with:</p>
  
  <pre><code>/bin/bash: activate: No such file or directory
  </code></pre>
  
  <p>Not really sure what I am doing wrong here. Can somebody please point me in the right direction?</p>
  
  <p>PS: It works with <code>source $(conda info --root)/etc/profile.d/conda.sh</code>, but I can't really use it since I need to support Windows as well!</p>
  
  <p>Disclaimer: I am new to <code>python</code>/<code>anaconda</code>.</p>