Python Tutorial › Getting Started › PyCharm & VS Code Setup

PyCharm & VS Code Setup

BeginnerLesson 4 of 479 min read1 runnable examples

An IDE (integrated development environment) gives you autocomplete, error highlighting, a run button and a debugger. This lesson sets up the two most popular free choices, PyCharm and Visual Studio Code.

Advertisement
In this lesson
  • Create a Python project in PyCharm
  • Set up VS Code with the Python extension
  • Select the right interpreter
  • Run and debug a script with breakpoints

Which editor should you choose?

PyCharm (Community or Pro)VS Code + Python extension
Made forPython onlyMany languages
SetupWorks out of the boxInstall the Python extension
StrengthsRefactoring, inspections, test runnerLightweight, huge extension library
Best forPython-focused learners and teamsPeople who also write JavaScript, YAML, etc.

Both are free for learning. Pick one and stick with it while you learn; the Python you write is the same.

Set up PyCharm

  1. Download PyCharm from jetbrains.com and install it.
  2. Click New Project. Give it a name such as python-practice.
  3. Under Interpreter type choose Project venv. PyCharm creates a virtual environment (a private copy of Python for this project) in a .venv folder.
  4. Click Create. Right-click the project folder, choose New > Python File, and name it first.py.
  5. Paste the program below and click the green Run arrow next to the first line.

Set up VS Code

  1. Install Visual Studio Code from code.visualstudio.com.
  2. Open the Extensions view (Ctrl+Shift+X), search for Python and install the extension published by Microsoft. It also installs Pylance for autocomplete.
  3. Use File > Open Folder to open an empty folder for your practice files.
  4. Press Ctrl+Shift+P, run Python: Create Environment, choose Venv and your installed Python.
  5. Create first.py, paste the program below and press the Run Python File triangle in the top right.

Your first program in the IDE

first.py
total = 0for price in [120, 80, 45]:    total = total + price    print("Running total:", total) print("Final total:", total)
Output
Running total: 120
Running total: 200
Running total: 245
Final total: 245
Tip

The Run window shows the same output as the terminal. If you see a ModuleNotFoundError for a package you installed, the IDE is using a different interpreter. Check the interpreter name in the bottom-right status bar.

Debug with a breakpoint

A breakpoint pauses the program on a line so you can inspect variables.

  1. Click in the gutter left of the line total = total + price. A red dot appears.
  2. Start the program with Debug (the bug icon) instead of Run.
  3. The program stops at the red dot. The Variables panel shows price and total.
  4. Press Step Over (F8 in PyCharm, F10 in VS Code) to run one line at a time and watch total grow.
Note

Debugging is the fastest way to understand someone else’s code, including the practice program solutions on this site. Step through a solution and watch each variable change.

Useful shortcuts

ActionPyCharmVS Code
Run current fileShift+F10Ctrl+F5
DebugShift+F9F5
Comment / uncomment lineCtrl+/Ctrl+/
Reformat codeCtrl+Alt+LShift+Alt+F
Find anythingShift ShiftCtrl+P

Check your understanding

Quick quiz

1. What does a virtual environment give your project?

2. Where do you set a breakpoint?

3. A package works in the terminal but the IDE says ModuleNotFoundError. What is the likely cause?

Program Practice

Create a basic-programs folder in your project and solve each program in its own file.

IDE setup FAQ

Is PyCharm Community Edition free?

Yes. PyCharm has a free tier for Python development, and VS Code with the Python extension is free as well.

Can I use IDLE instead?

Yes. IDLE comes with Python and is fine for small scripts. Move to PyCharm or VS Code when you want a debugger, a test runner and Git support.

What is a Python interpreter in PyCharm?

It is the Python executable PyCharm uses to run your code, usually the one inside the project’s .venv folder. You can change it in Settings > Project > Python Interpreter.