How to set up Python on Visual Studio Code
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
💻 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.
🛠️ 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
💡Visual Studio Code
💡Anaconda
💡Terminal
💡Extensions
💡Code Runner
💡Settings.json
💡Python.org
💡Command Prompt
💡File Extension
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
hey there hope you're having a wonderful
day in this video i'm going to show you
how to set up
python with visual studio code so most
people like to use
pycharm when they're writing python code
or anaconda with spider
i prefer visual studio code i think it's
much easier to use and it's more
convenient if you're working with other
languages as well
so first we want to install python so
what i'm going to do first
is go to terminal or command prompt and
check which version i have
so to do that i'll just type python dash
dash version
and you can see i am on 3.8.3 with
python commands you can also just type
pi instead of python it saves you four
characters
so pi dash dash version and
we get the same thing if you do not have
python on your machine
for instance if i type python
like this you might get something like
this where it says python is not
recognized as an internal or external
command
so this just means that you don't have
python on your machine so let's install
that
so go to python.org go to downloads and
click this right here
for me it says download for windows
because i'm using windows but for you
if you're using a mac or linux then it
will say download for mac or linux
so click that okay so now we have it
downloaded so click it to install it and
then just click install now
so after you have installed go to
code.visualstudio.com
make sure it's the blue one it says
visual studio code
not the purple one the blue one so for
you it might say down for mac or linux
for me it says download for windows so
just click this button whatever it says
and then now we can open it and you'll
get this pop-up
just accept agreement next
you want to click create a desktop icon
and then click next
and then click install i already have it
installed so i'm not going to click it
but just click install
and then afterwards you should see
visual studio code on your desktop
you can double click it or you can drag
it to your taskbar
if you are going to code frequently
so just click that and you'll see we
have
uh this uh setup we're going to create
file
and click ctrl s to save it so i'm going
to
save it to my desktop let's name it test
dot
python so make sure you include the
extension for python it's
py or pi so let's save that
and then here you can see your python
file we can create another one
so let's do test2 dot pi
and here's our second file so make sure
you include the extension
and in file 1 or test.pi i'm going to
put print
this is file 1 and print
let's say 50. so this is just outputting
to the console or terminal
and then for the other one i'm going to
say print file 2
and let's print 100
okay so you can see both of them are
created on our desktop
we go on terminal and
we type in python or pi and we go to the
directory of our file so desktop
slash test.pi
and you see this is file150 and i can do
test 2 and this is file 2 100
or you can just change directory to
desktop
and type pi test.pi
or pythontest.pi either one works and we
can do test2 as well
so this is how you would run your uh
python files
but with visual studio code we have an
editor so let's not do that we have our
built-in terminal
over here and we can just copy and paste
the command we did
so cd desktop
and just do pi test.pi and you'll see
this is file 150
okay but you might have noticed that i
have this run button over here so i can
just click this
and it will execute that command for me
so i don't have to type all that i just
need to click this button
you probably don't have this button so
let's go install that
so go to this block here extensions
first thing you want to do is install
python so
search for python and look for the one
by microsoft and click install
and then afterwards look for code runner
it's the one with this logo just click
install and then after you install this
you should have this run button over
here
and then now you can just click run code
when you run your code it might not
output to the terminal
it might output to the visual studio
built-in console the output console and
the problem with this is this is a
read-only console that means if you were
to
ask the user for an input you can't type
anything in
you can't type in any commands we want
it we want to set it to the terminal
so to change it to the terminal go to
this gear icon click this icon
and click settings and then scroll
down until you see
right here called actions on save click
edit in
settings.json
and then what you want to do is you want
to add this line
i will copy and paste this into the
description
so code runner dot run in terminal
set it to true and then afterwards when
you hit the run button
it should go to the terminal okay
and another thing you can do is
we can put these files in our folder
so let's create a folder here new
folder let's call it python files
so i'm going to drag these two in here
and then now i have two
files in my python files folder i can
just drag this
onto the visual studio code icon and you
can see
over here i have these two files okay
and if you don't want to do that if you
have it somewhere else that is not on
your desktop and you don't want to
go through your directories to find it
you can just use the terminal
and just go cd so i'm already in the
desktop but if you're not in the desktop
just go
cd desktop and then cd
stands for change directory so cd to
your folder so in my case it's python
files
and just type in code dot
and then this will open up visual studio
code okay
so that's how you set up python with
visual studio code
if you enjoyed this video and it worked
for you make sure to
leave a like and subscribe for more
updates on
python tutorial videos and all that fun
stuff
all right thank you for watching and
i'll see you later bye
Посмотреть больше похожих видео
Python Tutorial for Beginners with VS Code 🐍
#2 Python Tutorial for Beginners | Python Installation | PyCharm
手把手教大家搭建Autogen|微軟的多智能體協作系統|多AI協調|#multi-agent #autogen #openai #chatpgt #gpt4 #gpt #web3
Learn Visual Studio Code in 7min (Official Beginner Tutorial)
2 | How to Install a Local Server for PHP | 2023 | Learn PHP Full Course for Beginners
How to Install and Run Multiple Python Versions on macOS | pyenv & virtualenv Setup Tutorial
5.0 / 5 (0 votes)