Skip to content
PythonPython Foundationsbeginner30 min read

Installing Python and Choosing a Tool

Install Python, verify your setup, choose a code editor, and learn to run Python programs from a terminal or interactive shell.

In this lesson, you will learn

  • ✓Explain the difference between the Python interpreter, a code editor, an IDE, and a terminal.
  • ✓Choose an appropriate way to install Python for a beginner.
  • ✓Verify a Python installation and identify the interpreter version.
  • ✓Run a Python statement in the interactive shell and execute a saved .py script.
  • ✓Explain the difference between the interactive shell and script execution.
  • ✓Recognize and troubleshoot common installation, PATH, and file-location errors.

1. What Do You Need to Run Python?

A basic Python development setup has three important parts: a Python interpreter, a place to write code, and a way to run commands.

The Python interpreter is the software that runs Python code. Installing Python normally provides an interpreter and standard-library modules. The exact files and installation options depend on your operating system and distribution.

A code editor lets you create and edit source files. Examples include Visual Studio Code and other text editors. An integrated development environment (IDE) combines editing with additional development features such as running programs, debugging, and project navigation.

A terminal is a text-based interface where you enter operating-system commands. You can use it to check your Python installation, navigate to a project directory, and execute a Python script.

These tools have different responsibilities. An editor does not automatically replace the Python interpreter, and opening a .py file in an editor is not necessarily the same as executing it.

A statement that Python can execute

A statement that Python can execute
python
print('Python is ready')
Output
Python is ready

This is Python source code. A Python interpreter executes the statement. The built-in print() function displays the text. An editor can store this statement in a file, while a terminal can launch the interpreter to execute that file.

Note

Remember the distinction: Python executes the program, an editor helps you write it, and a terminal lets you issue commands to run it.

2. Install Python on Your Operating System

Use a trusted distribution for your operating system. The official Python website provides downloads and installation guidance at https://www.python.org/downloads/.

On Windows, the official Python installation options depend on the current release and distribution. Follow the official Windows documentation. After installation, you may be able to launch Python with the py launcher or the python command. Availability depends on your installation.

On macOS, download Python from the official Python website or use a trusted package manager if you already use one. Do not assume that a command named python points to the version you just installed.

On Linux, Python 3 is often provided by the distribution package manager. Many Linux system tools depend on the system Python, so avoid replacing or removing it casually. Follow your distribution documentation and use a separate virtual environment for project dependencies when appropriate.

You do not need to install every available Python version. For a beginner, one supported Python 3 installation is usually enough to start learning.

During installation, read the options carefully. On Windows, an installer or distribution may offer options affecting command availability or PATH configuration. These options vary by installer; follow its official instructions rather than assuming every installer has the same checkbox or behavior.

Official download page

Official download page
text
https://www.python.org/downloads/
Output
Open the official Python downloads page in your browser.

Select the instructions and download appropriate for your operating system. Use a supported Python 3 release. Complete the installation according to the official instructions. After installation, open a new terminal and verify that the interpreter is available.

Note

Installation commands are operating-system commands, not Python statements. Run them in your terminal, not at the >>> Python prompt.

3. Verify That Python Is Installed

After installation, check that your terminal can locate a Python interpreter. The command varies by operating system and installation method.

On Windows, try py --version or python --version. On macOS and Linux, try python3 --version. Depending on your setup, python --version may also work.

A successful version check prints a Python version, such as Python 3.x.y. The exact version depends on the installed release, so do not expect every computer to show the same number.

If the command is not recognized or the shell reports that the command cannot be found, the interpreter might not be installed, its command might differ, or its installation directory might not be available through PATH. Check the official instructions for your platform.

If several Python versions are installed, the command you use determines which interpreter is selected. Check the version and executable path when you need to know exactly which installation is running.

Check the installed Python version

Check the installed Python version
bash
python --version
Output
Python 3.x.y # Illustrative version format

Enter this command in a terminal where python is available. The interpreter responds with its version. The x and y characters are placeholders, not literal version digits. If the command is unavailable, try the platform-appropriate command described above.

Note

The version-check output is illustrative. Your installed Python version will determine the actual digits.

4. Understand the Interactive Python Shell

Python provides an interactive mode in which you can enter expressions and statements directly. It is useful for learning syntax, checking small calculations, and testing ideas without creating a file.

To start the interactive shell, enter the appropriate Python command without a script filename. For example, python, python3, or py may work depending on your system.

When the shell starts, it commonly displays the >>> prompt. Enter a Python statement after that prompt and press Enter. The shell executes it and shows the result when appropriate.

The >>> characters are the shell prompt; they are not part of the Python statement. When copying code into a .py file, do not include the interactive prompt.

To leave the interactive shell, use exit() or the platform-specific keyboard shortcut documented by your Python installation.

Try an expression interactively

Try an expression interactively
python
>>> 10 + 5
Output
15

The >>> prompt indicates that the interactive shell is ready for input. Enter 10 + 5 after the prompt. The shell evaluates the expression and displays the result. In an ordinary Python script, an expression by itself does not necessarily display its value. Use print() when you want explicit output.

Note

The interactive shell is ideal for quick experiments. Use a saved script when you want a program that you can edit, rerun, and share.

5. Create and Run Your First Python File

A Python script is a file containing Python statements. The conventional file extension is .py. For example, hello.py is a Python source file.

Create a new file in your chosen editor, enter the code below, and save it as hello.py. Ensure that your editor does not accidentally save the file with an extra extension such as .txt.

Open a terminal in the directory containing the file. On Windows, python hello.py or py hello.py may work. On macOS and Linux, python3 hello.py is a common choice. Use the command that corresponds to your installation.

When you run the script, Python executes the statements in the file in order. If the script contains print() calls, their output appears in the terminal.

If the command reports that the file cannot be found, check the current directory and the exact filename. The terminal must be able to locate the script at the path you supplied.

Contents of hello.py

Contents of hello.py
python
message = 'Hello from a Python file'
print(message)
Output
Hello from a Python file

The first statement binds message to a string. The second statement retrieves the value and displays it. Save both lines in a file named hello.py. Run the file using the Python command supported by your operating system.

Note

Keep terminal commands separate from Python code. The command python hello.py launches the script; it does not belong inside hello.py.

6. Choose a Development Tool

There is no single editor that every Python developer must use. Choose a tool that matches your current needs and computer.

Visual Studio Code is a general-purpose code editor that can support Python development through extensions. For a comfortable workflow, install the Python extension and select the interpreter you intend to use.

IDLE is included with many standard Python installations and provides a simple editor and interactive shell. It is a reasonable option when you want to start without configuring a larger editor.

PyCharm is an IDE designed for Python development. It provides project navigation, code assistance, debugging, and other features. Its available features depend on the edition and version.

Jupyter notebooks are useful for interactive experiments, data analysis, and teaching. They organize code into cells and can display results alongside the code. They are not necessary for learning basic Python syntax.

An online Python environment can be useful if you cannot install software on a computer. However, online tools may have limitations involving file access, packages, execution time, privacy, or internet connectivity.

For a beginner, the best tool is one that lets you reliably write, run, and debug small programs. Avoid spending too much time comparing editors before you have learned the basics.

The same Python program works in different editors

The same Python program works in different editors
python
name = 'CodeNivo'
print('Welcome to', name)
Output
Welcome to CodeNivo

This is ordinary Python source code. It can be saved in a .py file and run using a compatible Python interpreter. An editor changes how you write and manage the file, not the basic meaning of these statements. The output remains the same when the code is run successfully with a compatible interpreter.

Note

An editor, IDE, terminal, and interpreter serve different purposes, although some tools combine several of these features.

7. Common Setup Errors and How to Fix Them

Setup problems are common when you are new to programming. Most can be diagnosed by identifying whether the issue concerns the interpreter, the command, the file path, or the program itself.

Command not found or not recognized: the command may be unavailable, Python may not be installed, or the installation directory may not be on PATH. Check the appropriate installation instructions and open a new terminal after changing environment settings.

Wrong Python version: several interpreters may be installed. Use the relevant launcher or executable and check its version before running your project.

File not found: the terminal may be in a different directory from the file. Check the current directory, filename, spelling, and extension.

SyntaxError: Python found invalid syntax in the program. Inspect the indicated line for missing quotation marks, unmatched parentheses, or other syntax mistakes.

The editor uses a different interpreter: an editor or IDE may select a Python installation that differs from the terminal default. Check the interpreter selected by the editor.

Permission errors can arise from directory permissions or how the software was installed. Do not run every command as an administrator or root user to bypass an unexplained error.

Diagnose a filename problem

Diagnose a filename problem
bash
python hello.py
Output
Example error: cannot open file hello.py

This illustrative error can occur when Python cannot locate the requested file. Check whether hello.py exists in the terminal current directory. Check the filename and extension carefully. Change to the correct directory or provide the correct file path. The exact error message varies by operating system and Python version.

Note

Read the actual error message before changing settings. Fix the underlying problem rather than reinstalling Python immediately.

8. Verify Your Complete Setup

Before moving to more complex programs, confirm that your environment can run a saved script from beginning to end.

First, check the interpreter version. Next, create a .py file, save a simple program, and run it from a terminal. Confirm that the output matches what you expect.

If you use an editor or IDE, check that it selects the intended Python interpreter. If the terminal works but the editor does not, the problem may be the editor configuration rather than the Python installation.

You are ready to continue when you can create a file, execute it, read its output, and locate the file again without relying on guesswork.

Final environment check

Final environment check
python
print('Setup complete')
print(2 + 3)
Output
Setup complete 5

The first statement displays a confirmation message. The second statement calculates 2 + 3 and displays 5. Save both statements in a .py file and execute it. If both lines appear in order, you have verified a basic script execution workflow.

Note

A successful test confirms that this basic workflow works. It does not guarantee that every optional package or every development tool is configured.

Common pitfalls to avoid

Real debugging lessons and exact syntax contrasts to avoid runtime bugs

#1 Confusing the editor with the Python interpreter.

Why it happens: Editors and interpreters often appear together in an IDE, which can make their separate roles unclear.

Incorrect Approach
script.py
python
Confusing the editor with the Python interpreter.
Correct Solution
script.py
python
The editor helps you write source code; the interpreter executes it. Some IDEs integrate both workflows, but their roles remain distinct.

Key takeaway: The editor helps you write source code; the interpreter executes it. Some IDEs integrate both workflows, but their roles remain distinct.

#2 Entering terminal commands at the Python >>> prompt.

Why it happens: The terminal and Python interactive shell look similar, but they accept different kinds of input: shell commands versus Python expressions.

Incorrect Approach
script.py
python
Entering terminal commands at the Python >>> prompt.
Correct Solution
script.py
python
Run commands such as python --version and python hello.py in your operating-system terminal. Enter Python expressions at the interactive shell prompt.

Key takeaway: Run commands such as python --version and python hello.py in your operating-system terminal. Enter Python expressions at the interactive shell prompt.

#3 Assuming python, python3, and py work identically everywhere.

Why it happens: Python installations and operating systems expose different command names, so assuming one command works everywhere can cause confusing errors.

Incorrect Approach
script.py
python
Assuming python, python3, and py work identically everywhere.
Correct Solution
script.py
python
Command availability depends on your operating system and installation. Check the appropriate command and verify its version.

Key takeaway: Command availability depends on your operating system and installation. Check the appropriate command and verify its version.

#4 Assuming a successful installation means every terminal can locate Python.

Why it happens: A successful installation does not guarantee that the command is available in every terminal; PATH and launcher configuration affect command discovery.

Incorrect Approach
script.py
python
Assuming a successful installation means every terminal can locate Python.
Correct Solution
script.py
python
Check the command in a new terminal. If it is unavailable, investigate PATH, launcher availability, and the installation instructions.

Key takeaway: Check the command in a new terminal. If it is unavailable, investigate PATH, launcher availability, and the installation instructions.

#5 Saving a script in one folder and running it from another without providing a path.

Why it happens: A command runs relative to the terminal's current working directory, so the script may not be found if the terminal is elsewhere.

Incorrect Approach
script.py
python
Saving a script in one folder and running it from another without providing a path.
Correct Solution
script.py
python
Move the terminal to the folder containing the file or supply the correct path to the script.

Key takeaway: Move the terminal to the folder containing the file or supply the correct path to the script.

#6 Assuming an editor automatically uses the same interpreter as the terminal.

Why it happens: An editor can be configured to use a different Python interpreter or environment from the one used in the terminal.

Incorrect Approach
script.py
python
Assuming an editor automatically uses the same interpreter as the terminal.
Correct Solution
script.py
python
Check the interpreter selected by the editor or IDE and compare it with the terminal interpreter if their behavior differs.

Key takeaway: Check the interpreter selected by the editor or IDE and compare it with the terminal interpreter if their behavior differs.

#7 Reinstalling Python whenever a command fails.

Why it happens: Reinstallation feels like a universal fix, but many setup failures come from a wrong command, directory, PATH, or interpreter selection.

Incorrect Approach
script.py
python
Reinstalling Python whenever a command fails.
Correct Solution
script.py
python
Read the error first. A command-name issue, incorrect directory, or editor configuration problem may not require reinstalling Python.

Key takeaway: Read the error first. A command-name issue, incorrect directory, or editor configuration problem may not require reinstalling Python.

Ready for hands-on challenges?

Test your skills with shuffled coding challenges in the Practice Arena.

Practice Arena →

Technical and placement interview questions

Frequently tested interview questions with detailed, full answers (click to expand)

Q1:What is the Python interpreter?
Answer:
The Python interpreter is the software that executes Python programs. In common CPython usage, source code is compiled into bytecode and evaluated by the runtime.
Q2:What is the difference between an interpreter and a code editor?
Answer:
A code editor is used to create and modify source code. An interpreter executes that code. An IDE can integrate an editor, interpreter selection, execution controls, and debugging features.
Q3:How can you check whether Python is installed?
Answer:
Use a version command in the operating-system terminal, such as py --version or python --version on supported Windows installations, or python3 --version on many macOS and Linux installations. Check the command and version available on the actual system.
Q4:What is the difference between interactive mode and script mode?
Answer:
Interactive mode accepts statements and expressions directly and displays expression results. Script mode executes statements saved in a file, commonly with a .py extension. In a script, use print() when you want to display a value.
Q5:What does PATH do?
Answer:
PATH is an environment variable containing directories that a command shell searches for executable programs. If the Python executable is not discoverable through the command being used, the shell may report that the command is unavailable. Other launchers or explicit executable paths may still work.
Q6:Why might python work on one computer but not another?
Answer:
Python command names and installation methods vary by operating system and configuration. One computer may provide python, another python3, and a Windows installation may provide the py launcher. Multiple installations can also affect which interpreter is selected.
Q7:What should you do if a Python script cannot be found?
Answer:
Check the terminal current directory, the exact filename and extension, and the path passed to the interpreter. Change to the correct directory or supply the appropriate path.
Q8:Why can an IDE and terminal run different Python versions?
Answer:
The IDE and terminal can be configured to use different interpreter executables or environments. Inspect the interpreter selected in the IDE and compare it with the interpreter launched in the terminal.

Key takeaways

  • A Python development setup needs an interpreter and a way to create and run source code.
  • Use the official Python website and operating-system-specific installation instructions.
  • Verify the installation by checking the interpreter version in a terminal.
  • The interactive shell is useful for quick experiments; saved .py scripts are useful for reusable programs.
  • Use the command supported by your system: python, python3, or the Windows py launcher where available.
  • Editors and IDEs help you write and debug code, but they may select different interpreters.
  • Diagnose command errors, file paths, and interpreter selection before reinstalling Python.
  • A successful setup test should save a script, execute it, and produce the expected output.
Was this lesson helpful?
Found an error? Report an issue

Related Topics & Next Steps

4 Recommended Lessons

Strengthen your Python foundation with these complementary core lessons: