Execute python code in VS code in your mude-base environment.

Execute python code in VS code in your mude-base environment.#

In a simple sense, Jupyter Notebooks are documents that consist of many cells. Some cells are formatted text (Markdown, like this one), others can be used to execute Python code. Because we have already set up a conda environment that includes the Python programming language, all we have to do is tell VS Code (VSC) which environment to use and it will take care of sending the code in the Python cells to the environment so that they can be executed as desired. Then the output from running that code is displayed in the space below the Python cell from which it was executed. Let’s try it with a simple print() statement!

\(\text{Task 5.1: Open file in VS Code}\)

Download this file (the one you’re looking at) and store it in a working directory like explained in the book

\(\text{Task 5.2: Run python cell}\)

Confirm that Python and your conda environment are working properly by running the cell below. If you did the installation correctly, this should involve the following:

  1. Click the triangular "run" icon next to the cell.
  2. At the top of your VSC window you will be asked to select a Python environment. Choose the conda environment you just created, mude-base
  3. Confirm that the output of the cell is generated as expected.
  4. That's it!
Note that you might also be prompted to install a few VSC extensions, if you did not already do so in exercise 3. Read the message carefully so you know what VSC is installing; however, note that you don't really have to do anything except hit "yes" because VSC is pretty good at getting Python to run on your computer.

import sys

print("If you're connected to the mude-base environment,\nit should show up in the path below:\n",sys.executable)
If you're connected to the mude-base environment,
it should show up in the path below:
 c:\Users\tomvanwoudenbe\AppData\Local\tudelft-conda\envs\mude-base\python.exe

By Tom van Woudenberg and Robert Lanzafame, Delft University of Technology. CC BY 4.0, more info on the Credits page of Workbook.