How to set up Python on Visual Studio Code

Kenny Yip Coding
19 May 202106:56

Summary

TLDRThis video tutorial guides viewers on setting up Python with Visual Studio Code, an alternative to PyCharm and Anaconda. It starts with checking the Python version and installing it from python.org if not available. The presenter then demonstrates installing Visual Studio Code from code.visualstudio.com and creating Python files. The video shows how to run Python scripts using the terminal and Visual Studio Code's built-in terminal. It also covers installing the Python extension and Code Runner for easier execution, and configuring settings for terminal output. Finally, it discusses organizing Python files in a folder and opening them in Visual Studio Code.

Takeaways

  • 💻 The video provides a tutorial on setting up Python with Visual Studio Code, an alternative to PyCharm or Anaconda.
  • 🔍 To check the installed Python version, use 'python --version' or 'pi --version' in the terminal or command prompt.
  • 🚫 If Python is not recognized, it indicates that Python is not installed on the machine.
  • 🌐 The tutorial guides to download Python from python.org and install it on the system.
  • 🖥️ Visual Studio Code is recommended for its ease of use and convenience when working with multiple programming languages.
  • 🔗 The video instructs viewers to download Visual Studio Code from code.visualstudio.com.
  • 📁 It's important to include the '.py' or '.pi' extension when saving Python files to ensure proper recognition.
  • 📝 The video demonstrates how to write simple Python scripts and run them using the command line.
  • 🛠️ To enhance the coding experience, the tutorial suggests installing the Python extension and Code Runner extension in Visual Studio Code.
  • ⚙️ The settings are adjusted to ensure that running Python scripts through Visual Studio Code outputs to the terminal.
  • 📂 The video concludes with organizing Python files into a folder and using the terminal to open the folder in Visual Studio Code.

Q & A

  • What is the preferred text editor for Python programming according to the video?

    -The video suggests that Visual Studio Code is the preferred text editor for Python programming over PyCharm or Anaconda.

  • How can you check the installed Python version on your system?

    -You can check the installed Python version by typing 'python --version' or 'pi --version' in the terminal or command prompt.

  • What does the message 'python is not recognized as an internal or external command' indicate?

    -This message indicates that Python is not installed on your machine or it is not added to the system's PATH variable.

  • What is the recommended website to download Python from the video?

    -The video recommends downloading Python from python.org by going to the 'downloads' section.

  • How can you install Visual Studio Code according to the video?

    -You can install Visual Studio Code by visiting code.visualstudio.com and downloading the appropriate version for your operating system.

  • What is the significance of the '.py' or '.pi' extension when creating a Python file in Visual Studio Code?

    -The '.py' or '.pi' extension is significant as it identifies the file as a Python script, which is necessary for the file to be recognized and executed as Python code.

  • How can you run a Python script from the terminal in the video?

    -You can run a Python script from the terminal by navigating to the script's directory and typing 'python script_name.py' or 'pi script_name.pi'.

  • What is the advantage of using the 'Run Code' button in Visual Studio Code as shown in the video?

    -The 'Run Code' button in Visual Studio Code allows you to execute the Python script without manually typing the command in the terminal, simplifying the process.

  • Why is it necessary to install the 'Python' extension and 'Code Runner' extension in Visual Studio Code?

    -The 'Python' extension provides support for Python in Visual Studio Code, while the 'Code Runner' extension allows you to run code directly from the editor.

  • How can you configure Visual Studio Code to run Python scripts in the terminal instead of the built-in console?

    -You can configure Visual Studio Code to run Python scripts in the terminal by going to settings, editing the 'actions on save' section in 'settings.json', and setting 'code runner.run in terminal' to true.

  • What is the suggested method to organize Python files in the video?

    -The video suggests creating a folder for Python files, such as 'python files', and then dragging the files into Visual Studio Code for organization.

Outlines

00:00

💻 Setting Up Python with Visual Studio Code

This paragraph introduces the process of setting up Python with Visual Studio Code, an alternative to PyCharm and Anaconda. The speaker prefers Visual Studio Code for its ease of use and versatility with multiple programming languages. The tutorial begins with checking the current Python version using the command line, and if Python is not installed, the speaker guides the audience to download and install it from python.org. After installing Python, the speaker instructs how to download and install Visual Studio Code from code.visualstudio.com, emphasizing to download the correct version for their operating system. The paragraph concludes with creating a Python file, saving it with the appropriate '.py' or '.pi' extension, and demonstrating how to run a simple Python script from the terminal.

05:02

🛠️ Enhancing Visual Studio Code for Python Development

The second paragraph focuses on enhancing the Visual Studio Code experience for Python development. It starts with the installation of necessary extensions: the Python extension by Microsoft and Code Runner, which provides a 'Run Code' button for executing Python scripts. The speaker then shows how to change the output destination from the built-in console to the terminal for better interactivity. Additionally, the paragraph covers organizing Python files into a dedicated folder and using the terminal to open the folder directly in Visual Studio Code. The tutorial ends with a call to action for viewers to like and subscribe for more Python tutorial videos, thanking them for watching.

Mindmap

Keywords

💡Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used for web development, data analysis, artificial intelligence, and more. In the video, Python is the primary programming language being set up and used with Visual Studio Code, indicating the video's focus on Python development.

💡Visual Studio Code

Visual Studio Code (VS Code) is a popular, free, and open-source code editor developed by Microsoft. It supports a wide range of programming languages and offers features like debugging, syntax highlighting, and extensions. The video emphasizes setting up Python with VS Code, suggesting it as a preferred editor for Python development over other tools like PyCharm or Anaconda.

💡Anaconda

Anaconda is a distribution of the Python and R programming languages for scientific computing, which aims to simplify package management and deployment. It comes with pre-installed data science libraries. The video mentions Anaconda as an alternative to Visual Studio Code for Python development, highlighting the variety of tools available for Python programmers.

💡Terminal

A terminal is a command-line interface where users can execute commands directly to interact with the operating system. In the script, the terminal is used to check the installed Python version and to run Python scripts, demonstrating its utility in software development for executing and testing code.

💡Extensions

In the context of VS Code, extensions are add-ons that enhance the editor's functionality, such as adding support for new programming languages or integrating new tools. The video instructs viewers to install the Python extension by Microsoft and Code Runner, which are essential for a smooth Python development experience within VS Code.

💡Code Runner

Code Runner is an extension for VS Code that allows users to run code within the editor. It supports multiple languages and is mentioned in the video as a tool to execute Python scripts directly from VS Code, which streamlines the development process by eliminating the need to open a terminal.

💡Settings.json

Settings.json is a configuration file in VS Code where users can customize the editor's behavior. In the video, modifying the settings.json file is shown as a way to change the output destination of the Code Runner extension to the terminal, which is a practical step for developers who prefer terminal-based outputs.

💡Python.org

Python.org is the official website for the Python programming language, where users can download the latest version of Python, access documentation, and learn about the community. The video instructs viewers to visit python.org to download Python, emphasizing it as the primary source for obtaining the Python interpreter.

💡Command Prompt

Command Prompt is a command-line interface on Windows operating systems that allows users to execute commands. The video uses the term interchangeably with 'terminal' and demonstrates its use to check the Python version and run Python scripts, highlighting the importance of command-line interfaces in software development.

💡File Extension

A file extension is the suffix in a filename that indicates the file type. In the video, the presenter saves Python files with the '.py' extension, which is the standard for Python scripts. This detail is crucial as it ensures that the files are recognized and executed correctly by Python interpreters.

Highlights

Introduction to setting up Python with Visual Studio Code as an alternative to PyCharm or Anaconda.

Checking the installed Python version using the command line.

Using 'pi' as an alternative command to 'python' for brevity.

Instructions on installing Python if it's not recognized on the system.

Downloading Python from python.org and selecting the appropriate version for the operating system.

Installing Visual Studio Code from code.visualstudio.com.

Creating a Python file in Visual Studio Code and saving it with a '.py' extension.

Writing simple print statements in a Python script.

Running a Python script from the terminal using 'python' or 'pi' command.

Using the built-in terminal in Visual Studio Code to run Python scripts.

Installing the Python extension and Code Runner extension in Visual Studio Code.

Enabling the 'Run in Terminal' option for Code Runner to execute scripts in the terminal.

Creating a folder to organize Python files and opening it in Visual Studio Code.

Using the terminal to navigate to a folder and open it in Visual Studio Code with a single command.

Encouragement to like and subscribe for more Python tutorial videos.

Transcripts

play00:00

hey there hope you're having a wonderful

play00:01

day in this video i'm going to show you

play00:03

how to set up

play00:04

python with visual studio code so most

play00:07

people like to use

play00:08

pycharm when they're writing python code

play00:10

or anaconda with spider

play00:12

i prefer visual studio code i think it's

play00:14

much easier to use and it's more

play00:15

convenient if you're working with other

play00:17

languages as well

play00:19

so first we want to install python so

play00:21

what i'm going to do first

play00:23

is go to terminal or command prompt and

play00:25

check which version i have

play00:27

so to do that i'll just type python dash

play00:29

dash version

play00:31

and you can see i am on 3.8.3 with

play00:34

python commands you can also just type

play00:36

pi instead of python it saves you four

play00:38

characters

play00:39

so pi dash dash version and

play00:42

we get the same thing if you do not have

play00:45

python on your machine

play00:46

for instance if i type python

play00:50

like this you might get something like

play00:52

this where it says python is not

play00:53

recognized as an internal or external

play00:55

command

play00:56

so this just means that you don't have

play00:58

python on your machine so let's install

play01:00

that

play01:01

so go to python.org go to downloads and

play01:04

click this right here

play01:05

for me it says download for windows

play01:06

because i'm using windows but for you

play01:08

if you're using a mac or linux then it

play01:10

will say download for mac or linux

play01:12

so click that okay so now we have it

play01:16

downloaded so click it to install it and

play01:18

then just click install now

play01:20

so after you have installed go to

play01:24

code.visualstudio.com

play01:25

make sure it's the blue one it says

play01:27

visual studio code

play01:28

not the purple one the blue one so for

play01:31

you it might say down for mac or linux

play01:34

for me it says download for windows so

play01:36

just click this button whatever it says

play01:39

and then now we can open it and you'll

play01:41

get this pop-up

play01:42

just accept agreement next

play01:45

you want to click create a desktop icon

play01:48

and then click next

play01:49

and then click install i already have it

play01:51

installed so i'm not going to click it

play01:53

but just click install

play01:54

and then afterwards you should see

play01:56

visual studio code on your desktop

play01:58

you can double click it or you can drag

play02:00

it to your taskbar

play02:01

if you are going to code frequently

play02:04

so just click that and you'll see we

play02:07

have

play02:08

uh this uh setup we're going to create

play02:10

file

play02:11

and click ctrl s to save it so i'm going

play02:14

to

play02:14

save it to my desktop let's name it test

play02:17

dot

play02:18

python so make sure you include the

play02:20

extension for python it's

play02:21

py or pi so let's save that

play02:24

and then here you can see your python

play02:26

file we can create another one

play02:30

so let's do test2 dot pi

play02:33

and here's our second file so make sure

play02:35

you include the extension

play02:38

and in file 1 or test.pi i'm going to

play02:41

put print

play02:42

this is file 1 and print

play02:46

let's say 50. so this is just outputting

play02:48

to the console or terminal

play02:51

and then for the other one i'm going to

play02:53

say print file 2

play02:55

and let's print 100

play02:58

okay so you can see both of them are

play03:01

created on our desktop

play03:02

we go on terminal and

play03:06

we type in python or pi and we go to the

play03:09

directory of our file so desktop

play03:11

slash test.pi

play03:15

and you see this is file150 and i can do

play03:18

test 2 and this is file 2 100

play03:22

or you can just change directory to

play03:24

desktop

play03:26

and type pi test.pi

play03:30

or pythontest.pi either one works and we

play03:33

can do test2 as well

play03:36

so this is how you would run your uh

play03:38

python files

play03:39

but with visual studio code we have an

play03:42

editor so let's not do that we have our

play03:44

built-in terminal

play03:45

over here and we can just copy and paste

play03:48

the command we did

play03:49

so cd desktop

play03:52

and just do pi test.pi and you'll see

play03:55

this is file 150

play03:56

okay but you might have noticed that i

play03:59

have this run button over here so i can

play04:00

just click this

play04:02

and it will execute that command for me

play04:04

so i don't have to type all that i just

play04:06

need to click this button

play04:07

you probably don't have this button so

play04:08

let's go install that

play04:10

so go to this block here extensions

play04:14

first thing you want to do is install

play04:15

python so

play04:17

search for python and look for the one

play04:19

by microsoft and click install

play04:21

and then afterwards look for code runner

play04:26

it's the one with this logo just click

play04:28

install and then after you install this

play04:30

you should have this run button over

play04:32

here

play04:34

and then now you can just click run code

play04:37

when you run your code it might not

play04:38

output to the terminal

play04:40

it might output to the visual studio

play04:43

built-in console the output console and

play04:47

the problem with this is this is a

play04:49

read-only console that means if you were

play04:51

to

play04:51

ask the user for an input you can't type

play04:54

anything in

play04:54

you can't type in any commands we want

play04:56

it we want to set it to the terminal

play04:59

so to change it to the terminal go to

play05:02

this gear icon click this icon

play05:05

and click settings and then scroll

play05:09

down until you see

play05:13

right here called actions on save click

play05:16

edit in

play05:17

settings.json

play05:20

and then what you want to do is you want

play05:22

to add this line

play05:23

i will copy and paste this into the

play05:25

description

play05:27

so code runner dot run in terminal

play05:30

set it to true and then afterwards when

play05:33

you hit the run button

play05:35

it should go to the terminal okay

play05:39

and another thing you can do is

play05:42

we can put these files in our folder

play05:46

so let's create a folder here new

play05:49

folder let's call it python files

play05:53

so i'm going to drag these two in here

play05:55

and then now i have two

play05:57

files in my python files folder i can

play06:00

just drag this

play06:01

onto the visual studio code icon and you

play06:04

can see

play06:04

over here i have these two files okay

play06:08

and if you don't want to do that if you

play06:10

have it somewhere else that is not on

play06:12

your desktop and you don't want to

play06:14

go through your directories to find it

play06:16

you can just use the terminal

play06:18

and just go cd so i'm already in the

play06:21

desktop but if you're not in the desktop

play06:23

just go

play06:23

cd desktop and then cd

play06:27

stands for change directory so cd to

play06:29

your folder so in my case it's python

play06:31

files

play06:32

and just type in code dot

play06:35

and then this will open up visual studio

play06:37

code okay

play06:39

so that's how you set up python with

play06:40

visual studio code

play06:42

if you enjoyed this video and it worked

play06:43

for you make sure to

play06:45

leave a like and subscribe for more

play06:47

updates on

play06:48

python tutorial videos and all that fun

play06:51

stuff

play06:52

all right thank you for watching and

play06:54

i'll see you later bye

Rate This

5.0 / 5 (0 votes)

相关标签
Python SetupVisual Studio CodeCoding TutorialPython 3.8Development ToolsCode EditorProgramming GuideIDE SetupPython CodingVSCode Extensions
您是否需要英文摘要?