Modern Python Projects Transcripts
Chapter: Your code editor
Lecture: Installing Python extension

Login or purchase this course to watch this video and the rest of the course contents.
0:00 After you install VSCode and you open it, you are greeted with this welcome page. It has some suggestions of what you can do at the beginning.
0:08 Since we'll be working with Python, let's click this Python link on the right side.
0:13 Let's click. OK, and now VSCode is installing Python extension for us after
0:19 it's done is going to reload the window and you can see that Python is installed
0:23 because it's no longer blue. If for some reason you don't have this window, you can always click this icon.
0:29 This will take you to the extensions marketplace and here you just need to search for Python. We already have it installed,
0:35 so it was displayed there by default. But let's say you want to install a different package,
0:42 you search for it in the extension marketplace and you just click this install button. So what is this Python extension?
0:48 Well, VSCode doesn't support Python out of the box. I think it only supports Typescript and JavaScript, so we have to use an extension.
0:57 With the Python extension, we get a bunch of additional features. First of all, syntax highlighting,
1:02 for Python, but also additional tools like IntelliSense, which gives us code completion and code navigation.
1:09 We get linting, so we can use Flake 8, Pylint and other tools like that. We get formatting, so we can use Black PEP out of PEP 8 another formatters
1:18 We also get different debuggers and, for example, VSCode will automatically detect Python virtual environments.
1:25 Don't worry. If you don't understand any of those features that I just listed, I will explain them in more details as we progress through this course.
1:34 So, now that we have Python extension installed, let's try to open a new Python file if we save it with .py
1:43 Extension, VSCode will automatically detect that it's a Python file and it's going to suggest some additional features.
1:51 So, first is going to open this Python get started page, but also, it's gonna suggest you to install a Linter.
1:57 Linter is a tool that points some easy to fix problems with your code, for example, when you import the module or function, and you don't use it or
2:05 when you try to use an undefined variable, since it's a very useful tool. It's worth installing it, by default we get the suggestion to install pylint.
2:15 We can either click install or we can select a different linter. I will go with pylint this time. As you can see, the installation was successful.
2:27 If you run into some troubles when installing, for example, maybe you have an old Python version and VSCode cant install
2:34 pylint. Don't worry. In the next chapter, I'm going to show you how we can use some additional tools like virtual environments and
2:40 pipx to install global packages, for the time being. If you get some errors with pylint, just ignore it. So, let's see pylint in action.
2:48 Let's go back to our file and let's try to reference a variable that was not
2:53 defined. You can see, we get this Reds quickly underscore and error message saying undefined
3:02 Variable name. So, linters are very useful tools that can help you spot errors in your code. Next thing you might want to do is to choose a different
3:12 Python interpreter, and if you click in this lower left corner, you can see there is the list of different interpreters.
3:19 This is the default Python 2.7. That comes by default on a macOS. And here are some more up to date Python versions that I have installed on my
3:28 computer. If you have a brand-new MacBook, then you'll probably have only this Python 2.7. And if you installed additional versions,
3:36 maybe with conda, maybe with some other package manager. You might see them here as well, to change which, Python version is being used.
3:43 Just click one of them. You might get some errors, especially if you're using Python 2.7. The first warning says that well,
3:50 you selected an old Python version, which is not recommended, and the other one says that linter is not installed because
3:56 well, we installed pylint for the previous version of Python. Now that we switched to 2.7, we would have to install it again.
4:04 And if you try to install, I think you're going to get an error, let's give it a try. Yeah, there is no Pip, so, if you get this error,
4:11 just ignore it. For now, let me go back to the more up to date version of Python. If for some reason you don't see this side bar will not sidebar,
4:21 but just bar and you can't change Python version by clicking here. You can do this from the command palette on the Mac Press control shift P.
4:31 And you will see a list off all the commands available in VSCode command palette is the most useful tool in VSCode,
4:39 and you will probably be using it often. So to select a different interpreter, just type interpreter and select this command.
4:48 And here again, you can change which version of Python you are using. Let's go back to this one and let's continue one last step of the set up
4:56 is to add code command to your terminal. That way you will be able to run code and the name of the file in
5:03 your terminal, and this will open that file in VSCode. You have to follow different steps depending on what operating system you use. For Mac and
5:11 Linux, you can open the command palette and search for command called install code command in path. When you run it VSCode will do everything for you.
5:22 However, if you're using windows, then this step is done during the installation,
5:26 so make sure you check the add to path option, when you install VSCode on windows After we have done this,
5:33 we can go to our terminal and open any files from there. So let's close it here. Actually, close all that.
5:41 Go to the terminal and we have a code command. Just let's restart, be sure it's working. code hello.py . And it opens file in the VSCode, right.


Talk Python's Mastodon Michael Kennedy's Mastodon