From the course: Introduction to Python: Learn How to Program Today with Python by Pearson
Choose a code editor - Python Tutorial
From the course: Introduction to Python: Learn How to Program Today with Python by Pearson
Choose a code editor
Okay, so when you are programming, you'll want to have a special application to work in your code. So you could use a regular text application like TextEdit or like Notepad, but they're not ideal. So generally what we use is something called an integrated development environment or IDE for short. The reason we do that is because it gives you a place to edit your source code, but it also provides error and syntax highlighting for the language of your choice. It also gives you a place to run and maybe debug your program, provides code suggestions, and then might even have cool features like refactoring. Say you can take a variable and rename it everywhere in your program. Okay, there also might be some more fun stuff that your IDE provides. The one that I'll be programming in for this course is called PyCharm. So to get it, you can go to jetbrains.com slash pycharm slash download okay so download that run through the default configuration you might need to restart your computer and then come back okay so once you have it downloaded and installed let's open it up And then you can open a new folder, navigate to where your intro to Python 2nd edition is. It might have main at the end if you downloaded a zip file. And then just open that whole folder. Inside, you can see the code structure here, or the file structure here. You can open and close that in the Project tab. And you can ignore the docs. Examples is going to have a bunch of example files that you can use for your future reference after this course is done. Problems has the problems that we'll be working through throughout the course. And then there are a few challenge examples, too, which are just a little bit harder than the problems. and usually it's a little interactive game that you can create. Okay, if you open it up, you might see on the bottom right here, this is where your Python interpreter is. So mine is currently set to 3.13, which is great. If you need to change it or if it's not configured properly, you can choose an interpreter here that's installed. And if you don't see yours at all, you can go to Add New Interpreter, Local Interpreter, choose the system one here, look for it in the dropdown. And if it's not there, the three dots will allow you to locate it and find where it is on your computer. Okay, so if you're not sure where it is on your computer, there are a list of potential locations that I've listed out here. So, why are we using PyCharm? Well, for one, it handles Python out-of-the-box. You don't have to install any extensions or plugins. And then it also has a lot of built-in Python features, like an integrated Python console, a special package installer window, and managing your virtual environment. that normally people will do through the command line. But if you're a beginner, you might be intimidated by the command line. And so PyCharm allows you to bypass all that. It also has a nice, easy settings interface, instead of having to configure a file, edit a JSON file. And then it's also full-featured enough for professional developers like me. It also has lots of awesome keyboard shortcuts, which I demo in this video, Lesson 4.4 of Next Level Python. Lesson 4.3 also looks at configuring PyCharm and doing run configurations. There is also a book on O'Reilly called Mastering PyCharm, which you might be interested in. So you do not have to use PyCharm to run this course. That's just what I'll be doing. so if you wanted to be able to follow along exactly, that's what I would recommend. Some other popular options for Python programming in general are VS Code, which would be another good option for this course. Just know, so this is Visual Studio Code, it supports lots of other languages and it's free, so I use it when I do my JavaScript development. Just note that you should install the official Python extension if you are going to use it for Python. Okay, Spyder is a common one if you're in data science and if you downloaded Python via Anaconda then Spyder will come pre-installed for you. JupyterLab or Jupyter Notebooks are also very popular in data science and it's good for showing the process but it's not like .py files, they're special notebook files so for that reason it's not recommended for this course since all of the files that I have in the content are .py files. Okay, so if you missed it in lesson 1.1, this is where you get the content from the GitHub repository here. And let's look at how to run Python now. So there are two modes. There's interactive mode, and this is when you open up the Python console. It's also called the the REPL because this is what it does. It reads some code, evaluates it on that line, and then print the output, and then loop over and do that over and over again. There's also script mode, which is how you would write a Python program. You would save it in a .py file, and the interpreter will read it from top to bottom, And we can test it out on this file in our code. So, first of all, let's open up the Python console. You can do that. There's a Python icon here. Okay, and then if your interface looks different and you're not sure where to find it, you can always go to View, Tool Windows, Python Console. All right, so when you see the three arrows here, that is the prompt that tells you that you are in the Python console running in interactive mode. So I can do a little bit of Python here. I can, it'll read it, evaluate it, give me an output, and do it over again. I can print hello world. And you can also see that, you know, The syntax highlighting that PyCharm comes with also works in its built-in console and code suggestions and lots of fun extra features that you wouldn't have in just the basic console. And then to run it in script mode, we would open up a file. So I'm going to go to examples, example one, first code. And then I'm going to right-click and run this file. This will print the output to here. If it says finished with exit code 0, that means everything was good and you had no problems. If it says finished with exit code 1, which would be in red, you would see an error. And the most likely reason is that you don't have the right version of Python configured. For example, Python 2 or Python 3.5 or lower does not support F strings. Okay, I'm actually going to update this here. Okay, it doesn't support F strings. So so that's why you might get that error. So make sure that you have a Python version that's 3.6 or higher running. Okay, and so that opens up in this Run tab. So if we wanted to get back to the Python console, we would just click over here to get back to it. So we can also run Python in the command line. The basic Python command will run the Python console, and then Python with a file name will run that .py file. But just note that you might have to update your Python command depending on how it's installed on your machine. OK, so we can go to the terminal. And I covered this in lesson 1.1 already. But just using the correct Python command to target the version that you want. And then, so for me, I'm going to use Python 3. If I just use Python 3 on its own, that will run the Python console. And then to exit out of the console, I'll use the exit function, and then parentheses afterwards to call that function. And then to run a file, so script mode, I'll use the Python 3 command again. I have a file called test.py. and then that'll run the file. Okay, so just a note, if none of those commands work on Mac or Linux, you can look up instructions for how to add Python to your path, but also know that it's not required for this course because we will be running everything through PyCharm from now on. And then also again, a note on Windows, if you don't have the Python command, try just py and then you can use this command dash 3.x or you know where it's 3.13 or something to target a specific version. Okay and then you would just use that in place of the Python command if you were running it in PowerShell. Okay lastly another way to run Python that I wanted to show you quickly was idle. So if I look up IDLE, this is the IDE that comes built in with Python when you install it from the website. And you can see I've got a different version for each of my different Python versions on my computer. So I'll open one of those up. It starts off with the REPL or the Python console. And then if I wanted to run a file, I could open up, here I've got test.py, and then run module. Okay, so when I started learning Python, I just used IDLE, which is pretty basic, but because you can't open up a whole folder and see the folder structure here, here. I wouldn't recommend it for this course. It'll just be a bit of a pain. Hey, if you wanted to work in Visual Studio Code or Spyder, that's fine. I will have some instructions on the GitHub readme on how to get those configured and running. But yeah, I would mostly recommend it if it's what you know that you're going to use for your day-to-day Python development. Anyways. Okay, and then in the next lesson, we're going to look at writing some actual Python code.