title: How to correctly set PYTHONPATH for Visual Studio Code
body: <p>How do I correctly set up the <code>$PYTHONPATH</code> variable for my workspace in VisualStudio Code?</p>
  
  <p><strong>Background Information</strong></p>
  
  <p>I have installed two versions of GNURadio:</p>
  
  <ol>
  <li><p>GNURadio version 3.7.11 installed by the Linux Mint package manager in <code>/usr/lib/python2.7/dist-packages/gnuradio</code></p></li>
  <li><p>GNURadio version 3.7.13.4 installed by PyBOMBS in <code>/home/tejul/Documents/gr13/default/lib/python2.7/dist-packages/gnuradio</code> (my prefix directory is <code>~/Documents/gr13/default</code>)</p></li>
  </ol>
  
  <p>I can use the newer version of GNURadio version only after I run the <code>setup_env.sh</code> script (which -- among other things -- adds <code>/home/tejul/Documents/gr13/default/lib/python2.7/dist-packages</code> to <code>$PYTHONPATH</code>) and then start python in the terminal</p>
  
  <pre><code>tejul@Wacom:~/Documents/gr13/default$ ls
  bin  etc  include  lib  libexec  setup_env.sh  share  src
  tejul@Wacom:~/Documents/gr13/default$ source ./setup_env.sh 
  tejul@Wacom:~/Documents/gr13/default$ python
  Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
  [GCC 7.3.0] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; from gnuradio import gr
  &gt;&gt;&gt; gr.version()
  '3.7.13.4'
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>Without modifying the $PYTHONPATH python -- naturally -- imports the older version of GNURadio.</p>
  
  <p>I want to write, run, and debug python scripts for the new version of GNURadio in the VisualStudio Code. I've been trying to understand the selection of <a href="https://code.visualstudio.com/docs/python/debugging#_pythonpath" rel="noreferrer">python interpreters</a>, <a href="https://code.visualstudio.com/docs/getstarted/settings" rel="noreferrer">workspaces</a>, and <a href="https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file" rel="noreferrer">environments</a> for VSCode.</p>
  
  <p>As far as I understand it, the VSCode workspace setting <code>python.pythonPath</code> is not to be confused with the environment variable <code>$PYTHONPATH</code>. <code>python.pythonPath</code> is the path to the <em>python interpreter</em> used for debugging or running the code, while <code>$PYTHONPATH</code> is the environment variable which python uses to <em>search for modules</em>. </p>
  
  <p>It looks like PyBOMBS did not install its own python interpreter into my prefix directory. So I need to use VSCode with my normal python interpreter located in <code>/usr/bin/python2.7</code>. So redefining VSCode's <code>python.pythonPath</code> or selecting another python interpreter would not help me.</p>
  
  <p>I need to let VSCode use my own version of the environment variable <code>$PYTHONPATH</code> which would tell my regular python interpreter to import modules preferably from <code>/home/tejul/Documents/gr13/default/lib/python2.7/dist-packages</code>.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>Following the <a href="https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file" rel="noreferrer">documentation</a>, I have created my own <code>.env</code> file in the workspace directory which sets the order of preference for locations from which python should import the modules. Alas, it has no effect on the python interpreter.</p>
  
  <p><a href="https://i.stack.imgur.com/YQOYS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YQOYS.png" alt="Showing that VSCode is ignoring my $PYTHONPATH setting"></a></p>
  
  <p>Can you see anything that I am doing wrong here? I have also tried:</p>
  
  <ul>
  <li>Setting the PYTHONPATH to one folder level higher, i.e. <code>/home/tejul/Documents/gr13/default/lib/python2.7</code>, this did not help</li>
  <li>Calling the variable <code>$PYTHONPATH</code> instead of <code>PYTHONPATH</code>, this did not help</li>
  <li>Restarting VSCode after each change of the <code>.env</code> file, this did not help</li>
  <li>Using double quotes around the path string, e.g. <code>PYTHONPATH="/home/tejul/Documents/gr13/default/lib/python2.7:/usr/lib/python2.7"</code>, this did not help</li>
  </ul>