title: VS Code - Switching Python versions in integrated terminal
body: <p>I have <code>VS Code v1.44.2</code> with Microsoft's <a href="https://marketplace.visualstudio.com/items?itemName=ms-python.python" rel="nofollow noreferrer"><code>vscode-python</code></a> extension installed on <code>Windows 10</code> machine. </p>
  
  <p>According to <code>vscode-python</code> documentation, it has the ability to set the correct python version in a newly launched integrated terminal window. </p>
  
  <p>That functionality works, sort of: for me, it seems to work only if the Python version picked from the version picker is <code>3.5.2</code>--the one that came with Microsoft's ML Server. Also, it works only if the integrated terminal being launched is <code>cmd</code>. </p>
  
  <p>When these two narrow conditions are satisfied, sure enough, as soon as you launch the integrated terminal, <code>vscode-python</code> runs <code>/path/to/ML Server/Python/executable/activate.bat</code> and if you did <code>python --version</code> at the command prompt thereafter, you would see:</p>
  
  <pre><code>Python 3.5.2 :: Anaconda 4.2.0 (64-bit)
  </code></pre>
  
  <p>Unfortunately, environment activation doesn't work in the case of several other Python version I have installed:<code>2.7.x</code>, <code>3.6.x</code>, <code>3.7.x</code>: not on <code>cmd</code> or <code>gitbash</code> and I suspect not on many other shells</p>
  
  <p>Looking at <code>vscode-python</code> source code, the reason is apparent: <code>vscode-python</code> looks for the <code>activate</code> script (<code>activate.bat</code>, <code>activate.sh</code>, <code>activate</code>) in the same folder as <code>python.pythonPath</code>, whereas these scripts are typically in a subdir of <code>python.pythonPath/Lib/venv/scripts</code>.</p>
  
  <p>The relevant code snippet from <code>vscode-python</code> repo (<code>src/client/common/terminal/environmentActivationProviders/baseActivationProvider.ts</code>) reproduced below:</p>
  
  <pre><code>    protected async findScriptFile(pythonPath: string, scriptFileNames: string[]): Promise&lt;string | undefined&gt; {
          const fs = this.serviceContainer.get&lt;IFileSystem&gt;(IFileSystem);
          for (const scriptFileName of scriptFileNames) {
              // Generate scripts are found in the same directory as the interpreter.
              const scriptFile = path.join(path.dirname(pythonPath), scriptFileName);
              const found = await fs.fileExists(scriptFile);
              if (found) {
                  return scriptFile;
              }
          }
      }
  </code></pre>
  
  <p>This method is called from <code>src/client/common/terminal/environmentActivationProviders/bash.ts</code>:</p>
  
  <pre><code>   public async getActivationCommandsForInterpreter(
          pythonPath: string,
          targetShell: TerminalShellType
      ): Promise&lt;string[] | undefined&gt; {
          const scriptFile = await this.findScriptFile(pythonPath, this.getScriptsInOrderOfPreference(targetShell));
          if (!scriptFile) {
              return;
          }
          return [`source ${scriptFile.fileToCommandArgument()}`];
      }
  
      private getScriptsInOrderOfPreference(targetShell: TerminalShellType): string[] {
          switch (targetShell) {
              case TerminalShellType.wsl:
              case TerminalShellType.ksh:
              case TerminalShellType.zsh:
              case TerminalShellType.gitbash:
              case TerminalShellType.bash: {
                  return ['activate.sh', 'activate'];
              }
              case TerminalShellType.tcshell:
              case TerminalShellType.cshell: {
                  return ['activate.csh'];
              }
              case TerminalShellType.fish: {
                  return ['activate.fish'];
              }
              default: {
                  return [];
              }
          }
      }
  </code></pre>
  
  <p>As is evident from these code snippets, if the integrated terminal is <code>gitbash</code>, <code>vscode-python</code> looks for <code>activate.sh</code> or <code>activate</code> in <code>python.pythonPath</code>, but not in its sub-directories.</p>
  
  <p>My online search for a work around didn't produce much. There are some answers that rely on aliasing or sourcing activate in <code>.bashrc</code> or <code>.bash_profile</code> but that doesn't solve my problem. </p>
  
  <p>Ideally, I would like to have the following functionality:</p>
  
  <ol>
  <li>When I set the Python version through VS Code (either command palette or status bar), if there is an integrated terminal open, it should automatically switch version. I suppose the same idea would apply to environments, as opposed to versions.</li>
  <li>When I launch an integrated terminal, it should launch with the correct version set. I am OK with an automatic call to appropriate <code>activate</code> file if required.</li>
  </ol>
  
  <p>I'm sure other <code>vscode-python</code> users have run into the same problem, and from the code snippet, the solution appears simple (allow search into <code>/venv/**/*</code>); just wanted to see if there might be a different way of achieving my end goals?</p>