Now when your program runs you will see some more useful information in the editor window that tells you what went wrong. To run your program in debug mode, click the debug run button instead of the usual run button. ![]() To prepare your program to run in debug mode, click the link to create a launch.json file. To activate debug mode, click the debug tab in the tab bar on the left. Running your program in this mode produces more useful information about what went wrong. If your program generates an error message, you will find it useful to run your program again in debug mode. The error message gives some details on what went wrong, including the fact that the error took place on line 4 in the print command. The program produced an error message starting with the word 'Traceback'. Running this program will give you some output that looks like this: Open that new folder in Code and create a file named arithmetic.py in that folder. Go to your projects folder and make a new folder inside that named Arithmetic. Visual Studio Code also includes some useful tools to help you track down and fix errors in your programs.įor the next example I am going to create a somewhat longer Python program that contains an error. When you are done working with a project in Code, you can close the project folder by selecting the Close Folder command from the file menu. That terminal pane will show you the output from the program. This will open a terminal pane in the bottom right-hand corner of the window. To run the program, click the run button in the upper right hand corner of the window. Your first Python program is now ready to run. To tell Visual Studio Code to use the Python interpreter in the CMSC210 environment, click the blue bar at the bottom of the window and select the Python interpreter in the CMSC210 environment from the list of interpreters that pops up. When we created the CMSC210 environment in Anaconda that set up a second Python interpreter in that environment. When you installed Anaconda you got one Python interpreter installed in Anaconda's base environment. Next, you will need to tell Visual Studio Code which Python interpreter to use to run your program. Type or copy and paste the following line of code into the hello.py file: py extension identifies this file as a Python source code file. Alternatively, you can select the New File command from the File menu. To do this, click on the new file button to the right of the folder name. The next step is to create a Python source code file in the project. Navigate to your Projects folder and select the Hello folder. To open this project folder in Visual Studio Code, click the files tab in the tab bar, then click the Open Folder button. ![]() You will be placing the project folders for each project in this course in that folder.įor our first example, create folder named Hello in your projects folder. You should start by making a Projects folder in a convenient location. Visual Studio Code expects you to create a folder for each programming project you work on. Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSignedĦ) Close the terminal by clicking the trash can icon at the top of the terminal pane. Windows users will have to run a couple of additional configuration steps to get Visual Studio Code to work with Anaconda:ġ) Locate the Anaconda folder in the Windows start menu and run the Anaconda PowerShell Prompt program.Ĥ) In Visual Studio Code select the New Terminal command from the Terminal menu.ĥ) In the terminal pane execute the command: Find the Python extension and click Install. This will bring up a list of extensions you can install. ![]() Start up Visual Studio Code and click the extensions tab in the tab bar on the left edge of the window. To configure Visual Studio Code to work with Python, you will need to install an extension in Visual Studio Code. Visual Studio Code is designed to work with many popular programming languages, including Python. Visual Studio Code is a popular open source code editor. Next, download the installer for Visual Studio Code from and run the installer. Name your new environment CMSC210 and make sure that the Python option is checked. ![]() To do this, click on the Environments tab in Navigator and then click the Create button at the bottom of the window. To help manage the Python system we will be using in this course you will need to create an Anaconda environment. You can download the installer for the Anaconda Individual Edition from Īfter you run the Anaconda installer, you should launch the Anaconda Navigator application. The software that we will be using to install and manage Python for us is Anaconda. For this course you will need to install a Python interpreter and a development environment that you can use to write Python programs.
0 Comments
Leave a Reply. |