Getting Started with Python in VS Code (Official Video) - 双语字幕

Today, we're diving into setting up Python in VS Code.
I'm going to guide you through step by step,
pointing out what extension to install, how to configure what's needed, and share some tips to optimize your development environment.
Whether you're a beginner or a seasoned developer, this video will get you...
up and running in no time.
Okay, so let's jump right in.
To get started with using Python with VS Code,
you have an option to install Python from its website, python.org, to download and install the latest version for your operating system.
whether on Mac or Windows.
But if you are on a Mac, you have a second option to install it using Homebrew.
If you don't have Homebrew, you'll just need to install it using this line from the terminal that you see here.
And it is the preferred method.
So that's what I'll go ahead and do.
I'll confirm I have Brew installed by hyphen-version.
And to install it, I'll simply type in brew install Python 3.
Now to check the version of Python that's been installed, Python, hyphen, hyphen version.
And there we go.
When installing from Windows, make sure you have the box add Python to path check on Windows, you'll want to use this command.
Now we used homebrew to install it, but we could have easily downloaded a package which would look like this and install it.
Now the next thing that we want to do is install Python extension.
Now, you might be asking, wait a minute, didn't I just install Python?
Why do I need to install the extension?
Well, what we actually installed before was the Python interpreter.
And if you dug into the documentation,
you'll start seeing that they refer to it as Python interpreter there,
which is essentially the runtime, which allows you to execute Python scripts and a suite of.
But what about if you want to do some fancy things like formatting, linting, and code navigation?
That's when the Python extension comes into play.
And when you install it, it will also install the Python debugger for debugging Python code.
And in addition to that, it will also include the extension for pylance, which is essentially IntelliSense.
So I'll go ahead and install the extension.
And you could see the extension for the debugger is installed as well as for pylance.
The thing that you want to do is create a virtual Once you activate that environment,
any packages you then install are isolated from other environments.
So let me just get started by creating a file that we'll call demo.py and then just add in a simple print statement.
We'll save that and just test it real quick by typing in python3demo.py.
Perfect.
Now if I wanted to add a package related to discord, the common approach is to use the pip command.
So if I did that,
you'll notice that I get this error because we're in a normal folder that knows nothing about the
pipe command and can't manage packages from here.
But we could solve this by creating a virtual environment.
So if I go to my command palette,
command shift P,
I can type in Python create environment or select it if I see it on the menu as I do here,
which then presents us a list of environment types of which I'll choose the first one.
Now we're presented with a list of interpreters that could be used for my project.
I'll choose the latest one 3.12 and you'll notice at the bottom the screen it's creating our environment and now at the blue status bar towards the
bottom.
You'll see our environment is indicated.
If you're needed to change it you could just click here to change it but we'll leave it as is.
You'll also notice on the left-hand corner, we have a new folder with the extension .vnv for our virtual environment.
That includes a bin, include, and lib folder, along with the configuration file.
If I try to run this command again,
it won't work, but that's just because we now need to essentially refresh our terminal by killing it.
control tick and now you can see the difference in the terminal because the prop begins with that vent.
I can clear the screen and now try to run my command for installing discord and it seems to be working
beautifully and we can confirm that by going to the library folder and we could see some discord folders that's been installed.
Before I forget if you like this kind of content we love it if you hit that subscribe and like button really helps the channel out.
Now earlier on I had showed you how I executed my python file just by using a simple command such as this but there's a couple
of things I want to show you.
The is that there's other ways to execute python files such as right here next to the play button.
If you hit the drop down there's a few options to run code run python file in dedicated terminal in addition to a couple of options for the bugger.
So I can go and run python.
and that will essentially have the same result, though with a little bit more content in the terminal.
The other thing that I want to out is that you can actually run several Python commands within the terminal by launching the REPL terminal.
So if I go to the command palette,
command shift P and type in REPL,
I'll get this option here to start terminal REPL and REPL stands for read evaluate print
loop and you know you're at the right spot when you see the three arrows to the left
and here I could put in some math equation if I wanted.
Hit gives me the answer and there's a lot more to do like what you see here.
In short, it's a great way to quickly experiment, debug, or test small code snippets with Python syntax without creating a new script file.
And when I'm ready to get out, I can just hit Ctrl D, and I'm back to where I was.
Now, there are a few things I want to show you in respect to code navigation and debugging, but that requires a little bit more code, so let's...
Now because of the extensions and the way that we set up our environment,
we have a lot more flexibility to navigate when we have a lot more code.
So for example,
I can go to one of my methods here,
like many of the IDEs, find all references and quickly be able to jump to any other part.
of the code that I want to examine.
The same applies to if I want to go onto a class and go to definition, it'll be right there.
When I'm actually coding, I have that great a telecent, that gives me information on any object I'm referencing, including functions in action.
attributes.
And more importantly,
when it comes to debugging,
if you recall,
when we click this drop down here,
we could begin the debugging process with the file here, or debug using a launch.json if we have one configured.
Now, I haven't done that yet, but I want to show you the other way to get that done is to come over here to the left hand pane and click run and debug and here
we can come to create a launch.json file at which point we could choose Python debugger and now we get to see all
these other Python projects that we can configure a launch.json file for whether it be fast API Django, Flask.
Let's go ahead and choose Python file.
And here, VS Code will give you the most common configuration, which is set up like this.
Now, if I wanted to add more configuration,
For my setup, I can just go ahead and click here, but I'm not going to do that now.
Configuring launch.json can be a whole video in itself,
and I actually do have another video on debugging in VS Code, which is going to be broken up into two parts.
So if you'd like to have that second part where I focus on launch.json configuration, include demonstrating python, comments, python launch.json.
For now I want to go ahead and just demonstrate the debugging process by first setting a breakpoint on line 20 and then on the left hand side clicking on the start debugging
play button.
And if you're familiar with the debugging process from other code editors this may you may seem familiar where we can step over method into out of restart the process and stop the
debugging process or just continue.
So if I want to go ahead and just step into this current method, it'll bring me there.
And you'll notice on the left hand side,
we could start monitoring variables such as
If we have any global variables or want to add specific variables to keep an eye on under watch, we can do that.
But at this point I just want to show how to get the debugging process started.
And there's another video completely on debugging.
But for now, you pretty much have all the basic requirements to move on with your development process.
With Python, in VS Code.
The thing that I want to show you is that a lot of the information that I covered in this video came right from the documentation which is done very well with lots of visuals
and step-by-step information.
So check it out to even cover topics that was not covered such as more details regarding setting things up in Django,
Fast API, Flask, topics such as testing, and a lot more.
And there you have it.
You've successfully set up Python and VS Code.
I hope you found this tutorial helpful to work on your Python projects.
If you learned something new and enjoyed this video,
Remember to hit that thumbs up and subscribe but also definitely leave some questions or
feedback in the comments below on any videos you'd like us to make in the future.
That's it for now and I will see you in the next one.
翻译语言
选择翻译语言

解锁更多功能

安装 Trancy 扩展,可以解锁更多功能,包括AI字幕、AI单词释义、AI语法分析、AI口语等

feature cover

兼容主流视频平台

Trancy 不仅提供对 YouTube, Netflix, Udemy, Disney+, TED, edX, Kehan, Coursera 等平台的双语字幕支持,还能实现对普通网页的 AI 划词/划句翻译、全文沉浸翻译等功能,真正的语言学习全能助手。

支持全平台浏览器

Trancy 支持全平台使用,包括iOS Safari浏览器扩展

多种观影模式

支持剧场、阅读、混合等多种观影模式,全方位双语体验

多种练习模式

支持句子精听、口语测评、选择填空、默写等多种练习方式

AI 视频总结

使用 OpenAI 对视频总结,快速视频概要,掌握关键内容

AI 字幕

只需3-5分钟,即可生成 YouTube AI 字幕,精准且快速

AI 单词释义

轻点字幕中的单词,即可查询释义,并有AI释义赋能

AI 语法分析

对句子进行语法分析,快速理解句子含义,掌握难点语法

更多网页功能

Trancy 支持视频双语字幕同时,还可提供网页的单词翻译和全文翻译功能

开启语言学习新旅程

立即试用 Trancy,亲身体验其独特功能

立即下载