1. Introduction
Before writing any Python program, you need a working Python interpreter installed on your machine and a comfortable environment to write and run code. This lesson covers installing Python 3 on the major operating systems, verifying the installation from the command line, and setting up a popular IDE or code editor (such as VS Code or PyCharm) for a smooth development workflow, including the use of virtual environments to isolate project dependencies.
Cricket analogy: Just as a player needs the right kit (bat, pads, spikes) fitted and broken in before stepping onto the pitch, a developer needs Python installed and an IDE like VS Code or PyCharm configured, with virtual environments keeping each 'match's' gear separate.
Getting the setup right early avoids common early frustrations like 'python: command not found', mismatched Python versions, or dependency conflicts between unrelated projects.
Cricket analogy: Just as arriving at the ground without your registered kit gets you turned away, skipping proper Python setup leads to frustrating 'python: command not found' errors and version mismatches before you even start coding.
2. Syntax
# Verify Python is installed and check its version (run in a terminal, not a .py file)
python3 --version
# or on some Windows installations:
python --version
# Check that pip (Python's package installer) is available
pip3 --version
# Create an isolated virtual environment for a project
python3 -m venv myproject-env
# Activate it (macOS/Linux)
source myproject-env/bin/activate
# Activate it (Windows PowerShell)
myproject-env\Scripts\Activate.ps1
# Install a package inside the active virtual environment
pip install requests3. Explanation
On Windows and macOS, the recommended approach is to download the official installer from python.org (or use a package manager like Homebrew on macOS: brew install python). On Linux, Python 3 is usually preinstalled or available via the system package manager (e.g., sudo apt install python3 python3-pip on Debian/Ubuntu). After installation, run python3 --version (or python --version) in a terminal to confirm the interpreter is on the system PATH and reports a Python 3.x version.
Cricket analogy: Just as different grounds have different pitch-preparation methods - roller for one, covered curator's mix for another - Windows and macOS use the python.org installer or Homebrew, while Linux typically ships Python 3 via apt, and 'python3 --version' confirms the setup like checking the pitch report.
For an editor, VS Code (with the official Python extension) and PyCharm are the two most widely used tools. Both provide syntax highlighting, autocomplete, integrated debugging, and built-in terminal access. A key best practice, regardless of editor choice, is to use a virtual environment (via the built-in venv module) per project — this creates an isolated set of installed packages so that different projects' dependencies don't clash.
Cricket analogy: Just as a well-equipped nets session offers a bowling machine, video analysis, and a dedicated coach, VS Code and PyCharm offer syntax highlighting, autocomplete, and integrated debugging, while a venv per project keeps each squad's (project's) gear separate.
Common gotcha: On many systems (especially macOS and Linux), the python command may still point to Python 2 or may not exist at all, while python3 reliably points to Python 3. Always verify with python3 --version and prefer python3/pip3 explicitly to avoid accidentally using the wrong interpreter or an unsupported Python 2 environment.
Exam-relevant nuance: pip installs packages into whatever Python environment is currently active. If you forget to activate your virtual environment before running pip install, the package gets installed globally (or into the wrong environment), which is a frequent source of 'ModuleNotFoundError' confusion for beginners.
4. Example
# setup_check.py -- a small script to confirm your Python installation is working correctly
import sys
import platform
def check_environment():
print("Python version:", platform.python_version())
print("Python executable path:", sys.executable)
print("Platform:", platform.system())
major, minor = sys.version_info.major, sys.version_info.minor
if major < 3:
print("Warning: You are running Python 2, which is unsupported. Please install Python 3.")
else:
print(f"Good to go! Running Python {major}.{minor}")
if __name__ == "__main__":
check_environment()5. Output
Python version: 3.12.4
Python executable path: /usr/local/bin/python3
Platform: Linux
Good to go! Running Python 3.126. Key Takeaways
- Install Python 3 from python.org, a package manager (Homebrew/apt), or your OS's official channels — never rely on outdated Python 2.
- Verify installation with
python3 --versionand confirm pip is available withpip3 --version. - On many systems
pythonmay not point to Python 3 — prefer the explicitpython3/pip3commands. - Use
python3 -m venv <name>to create an isolated virtual environment per project, then activate it before installing packages. - Popular editors/IDEs for Python include VS Code (with the Python extension) and PyCharm, both offering debugging and autocomplete.
- Installing packages without an active virtual environment can pollute the global environment and cause dependency conflicts across projects.
Practice what you learned
1. Which command is generally the most reliable way to confirm Python 3 is installed and check its version, especially on macOS/Linux?
2. What is the primary purpose of a Python virtual environment (created via `python3 -m venv`)?
3. A beginner runs `pip install requests` without activating any virtual environment, then later gets confused why a different project also seems to have `requests` available. What is the most likely explanation?
4. Which of the following are widely used code editors/IDEs for Python development?
5. On Debian/Ubuntu Linux, which command typically installs Python 3 and its package manager via the system package manager?
6. After creating a virtual environment with `python3 -m venv myenv`, what must you do before packages installed with pip will be isolated to that environment?
Was this page helpful?
You May Also Like
Introduction to Python Programming
An overview of Python as a high-level, interpreted, general-purpose language and why it is a popular first language for beginners and professionals alike.
Features of Python
A tour of Python's core language features — dynamic typing, simplicity, portability, extensive libraries, and more — that explain its widespread adoption.
Virtual Environments and pip in Python
Isolating project dependencies with venv and managing packages with pip -- creation, activation, and requirements files.
Modules and Packages in Python
Learn how Python organizes code into reusable modules and packages, and how the import system locates and caches them.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics