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,親身體驗其獨特功能

立即下載