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-субтитры

Создавайте точные и быстрые AI-субтитры YouTube всего за 3-5 минут.

AI-определение слов

Нажмите на слова в субтитрах, чтобы найти определения с помощью AI.

AI-анализ грамматики

Анализируйте грамматику предложений, чтобы быстро понять их значение и освоить сложные грамматические моменты.

Дополнительные веб-функции

Помимо двуязычных видео субтитров, Trancy также предоставляет перевод слов и полноэкранный перевод для веб-страниц.

Готовы начать

Попробуйте Trancy сегодня и оцените его уникальные возможности самостоятельно

Скачать