Before writing any Python code, you need to install Python on your computer and set up a development environment. An Integrated Development Environment (IDE) or a code editor helps you write, test, and debug your code efficiently.
In this tutorial, we will learn how to install Python and configure two of the most popular editors: Visual Studio Code (VS Code) and PyCharm.
Step 1: Downloading and Installing Python
Python is free and open-source. You can install it on Windows, macOS, or Linux. Follow these steps to install Python on a Windows machine.
1. Download Python
- Open your web browser and go to the official Python website: python.org/downloads.
- The website will automatically detect your operating system. Click the Download Python button to get the latest version.
2. Run the Installer
- Open the downloaded
.exefile. - Important: At the bottom of the installation window, check the box that says “Add Python to PATH”. If you skip this step, Python will not run from your command line.
- Click on Install Now.
- Wait for the setup to complete and click Close.
3. Verify the Installation
To confirm that Python is installed correctly:
- Open the Command Prompt (press
Win + R, typecmd, and press Enter). - Type the following command and press Enter:
python --version
- If the installation was successful, it will display the installed Python version (e.g.,
Python 3.13.1).
Step 2: Choosing an IDE or Code Editor
While you can write Python code in a simple text editor like Notepad, using a proper IDE makes coding much easier. It provides features like syntax highlighting, auto-completion, and debugging tools.
The two most widely used tools for Python are:
- Visual Studio Code (VS Code): A lightweight, fast, and highly customizable code editor.
- PyCharm: A dedicated, full-featured Python IDE developed by JetBrains.
Step 3: Setting up Visual Studio Code (VS Code)
VS Code is highly recommended for both beginners and working professionals because it supports multiple languages and has a huge marketplace of extensions.
1. Install VS Code
- Go to the official website: code.visualstudio.com.
- Download the installer for your operating system and install it using the default settings.
2. Install the Python Extension
- Open VS Code.
- On the left sidebar, click on the Extensions icon (or press
Ctrl + Shift + X). - Search for “Python” in the search bar.
- Find the extension published by Microsoft and click Install.
3. Write and Run Your First Program
- Create a new folder on your computer and open it in VS Code (
File > Open Folder). - Create a new file named
hello.py. The.pyextension tells VS Code that this is a Python file. - Type the following code:
print("Hello from VS Code!")
Code language: PHP (php)
- To run the code, click the Play button (Run Python File) situated at the top right corner of the editor. You will see the output in the terminal at the bottom.
Step 4: Setting up PyCharm
PyCharm is a powerful IDE specifically built for Python. It is widely used in enterprise-level software development. It comes in two versions: Professional (Paid) and Community (Free).
1. Install PyCharm Community Edition
- Go to the JetBrains website: jetbrains.com/pycharm/download/.
- Scroll down and download the Community Edition (which is free and open-source).
- Run the downloaded installer and follow the on-screen instructions to complete the setup.
2. Create a New Project
- Open PyCharm.
- Click on New Project.
- Choose a location for your project folder. PyCharm will automatically create a virtual environment for you. Click Create.
3. Write and Run Your First Program
- Right-click on your project folder in the left sidebar, select
New > Python File. - Name your file
main(PyCharm will automatically add.py). - Type the following code:
print("Hello from PyCharm!")
Code language: PHP (php)
- Right-click anywhere inside the code editor and select Run ‘main’. The output will appear in the run tool window at the bottom.
Which one should you choose?
- Choose VS Code if: You want a fast, lightweight editor that you can use for web development, frontend, and Python scripting all at once.
- Choose PyCharm if: You are working on large Python projects or Data Science workflows and want everything (environment management, database tools, advanced debugging) pre-configured out of the box.
Now that your environment is ready, you can move on to writing actual Python programs.
