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