Free lesson · Python Basic to Advance
Setting Up Your Environment
Setting Up a Python Environment
What "Setting Up Python" Actually Means
Setting up Python involves three separate decisions:
- Installing a Python interpreter on the machine
- Choosing a code editor or IDE
- Managing dependencies and project isolation
Each decision has multiple reasonable answers. This topic covers what to install and configure to start working productively. Module 11 covers package management and virtual environments in detail; this topic introduces them briefly so the rest of the early modules can be followed along.
Interactive animation: Setting up Python as three separate decisions - the interpreter, the editor, and a virtual environment per project.
Installing Python
The right Python version for this course is Python 3.13 or newer. Earlier versions work for most examples but may lack features used in later modules.
On macOS
Python comes pre-installed on macOS, but the bundled version is typically older and modifications to the system Python can break macOS itself. Install a separate, current Python:
Option 1: Official installer. Download from python.org and run the macOS installer. This is the most straightforward choice.
Option 2: Homebrew. If Homebrew is already installed:
brew install python@3.13
This shell command uses Homebrew to install Python version 3.13 on macOS.
Option 3: pyenv. For managing multiple Python versions side by side. Useful if working across projects with different version requirements:
brew install pyenv
pyenv install 3.13
pyenv global 3.13
These three shell commands install pyenv via Homebrew, install Python 3.13 through pyenv, and set Python 3.13 as the global default Python version for the user.
On Linux
Most Linux distributions ship with Python pre-installed. Check the version:
python3 --version
This shell command prints the installed Python 3 version to the terminal.
If the version is older than 3.13, install a newer one:
Debian/Ubuntu:
sudo apt update
sudo apt install python3.13 python3.13-venv
These two shell commands update the package list using apt, then install Python 3.13 and its virtual environment package. The sudo prefix runs the commands with administrator privileges.
Fedora/RHEL:
sudo dnf install python3.13
This shell command installs Python 3.13 on Fedora or Red Hat systems using the dnf package manager.
Arch:
sudo pacman -S python
This shell command installs the latest Python version on Arch Linux using the pacman package manager.
The system Python should not be replaced or removed; many OS tools depend on it. Install a newer Python alongside.
On Windows
Download the installer from python.org. During installation, check the box marked "Add Python to PATH" - without this, the python command won't work in a terminal.
The Microsoft Store version of Python also works but has known quirks with file paths and permissions. The python.org installer is the more reliable choice.
After installation, verify in PowerShell or Command Prompt:
python --version
This Windows command prints the installed Python version to the terminal.
Verifying the Installation
After installation on any platform, three commands should work:
python3 --version # On macOS/Linux
python --version # On Windows (or systems where python3 isn't aliased)
pip --version # Package manager
These three commands print the version of Python and pip. The first form, python3, is used on macOS and Linux. The second, python, is used on Windows or systems without a python3 alias. The third, pip version, checks that the Python package manager is also installed and reports its version.
Both python and python3 may be valid on the same system. Older systems may have python pointing to Python 2. When in doubt, use python3 to be explicit.
Interactive animation: Checking the install in a terminal - python3 --version and pip --version each report what is installed.
Choosing an Editor or IDE
Python development works in any text editor. Some choices are better than others.
Visual Studio Code
Free, widely used, and excellent for Python work. Install the Python extension from Microsoft to get:
- Syntax highlighting and code completion
- Integrated debugger
- Linting and formatting integration
- Jupyter notebook support
- Type hint checking
VS Code is the default recommendation for most Python developers.
PyCharm
Made by JetBrains. Two versions exist:
- Community Edition - free, supports general Python development
- Professional Edition - paid, adds web framework support (Django, Flask), database tools, and remote development
PyCharm is more opinionated than VS Code and provides deeper Python-specific tooling out of the box. Some engineers prefer it; others find it heavyweight.
Other Options
- Sublime Text - fast, requires more configuration for full Python support
- Vim/Neovim - for users already comfortable in modal editors; add LSP for code intelligence
- JupyterLab/Jupyter Notebook - for data science and exploratory work specifically; not a primary editor for application development
For working through this course, VS Code with the Python extension is the simplest path. Other choices are fine if already familiar.
Working Directory Conventions
Python projects typically follow a standard layout:
my-project/
README.md
requirements.txt # or pyproject.toml
.gitignore
src/ # source code (or sometimes at root)
my_package/
__init__.py
main.py
tests/
test_main.py
.venv/ # virtual environment (not checked into git)
This is a typical Python project directory layout. The root folder my-project contains a readme file, a requirements file listing dependencies, a gitignore file, a source folder containing the package code with init and main modules, a tests folder, and a dot-venv folder holding the virtual environment. The dot-venv folder is excluded from version control.
The exact structure varies; what matters is consistency within a project. For early examples in this course, a simple flat directory with .py files is sufficient. Project structure becomes more important in Modules 11 and beyond.
Virtual Environments (Preview)
Interactive animation: Project A needs requests 2.28, Project B needs 2.31 - a global install breaks one, a venv per project breaks neither.
Different Python projects often need different package versions. Installing all packages globally creates conflicts: Project A needs requests==2.28 while Project B needs requests==2.31.
A virtual environment is an isolated Python installation for a single project. Each project has its own packages without affecting the system Python or other projects.
Creating a virtual environment:
python3 -m venv .venv
This shell command runs Python 3 with the venv module to create a new virtual environment in a folder named dot-venv inside the current directory.
This creates a .venv directory in the current folder. Activate it:
macOS/Linux:
source .venv/bin/activate
This shell command sources the activate script from the virtual environment's bin folder. After running it, the shell's PATH is modified so that python and pip refer to the virtual environment's versions.
Windows (PowerShell):
.venv\Scripts\Activate.ps1
This PowerShell command runs the Activate dot ps1 script from the virtual environment's Scripts folder, which activates the environment on Windows.
Once activated, python and pip use the virtual environment. Install packages with:
pip install requests
This shell command uses pip to install the requests package into the active virtual environment.
Deactivate when finished:
deactivate
This shell command deactivates the current virtual environment, restoring the shell's PATH to use the system Python.
Module 11 covers virtual environments and dependency management in depth, including alternative tools like Poetry, uv, and pipx. For now, knowing how to create and activate a venv is enough.
A Minimum Working Setup
For working through this course:
- Install Python 3.13 using one of the methods above
- Install VS Code and the Python extension (or use a preferred editor)
- Create a directory for the course:
mkdir python-course && cd python-course - Create a virtual environment:
python3 -m venv .venv - Activate it
- Confirm
python --versionreports 3.13 or newer
The course can be followed with just this setup. Additional tools (linters, formatters, type checkers) are introduced in later modules.
Interview Relevance
Interview: Setup questions rarely appear directly in interviews, but candidates are expected to be fluent with virtual environments and basic dependency management. "How do you isolate dependencies between Python projects?" is a reasonable warm-up question that signals whether a candidate has shipped real Python code.
Module 30 covers Python interview preparation.
Common Pitfalls
Warning: Using the system Python on macOS or Linux. Modifications can break OS tooling. Install a separate Python.
Forgetting "Add Python to PATH" on Windows. Without it, terminal commands fail.
Confusing
pythonandpython3. On many systems,pythonis Python 2 or undefined. Usepython3to be explicit.Skipping virtual environments. Global package installation eventually causes version conflicts. Use a venv per project from the start.
Mixing pip and conda in the same environment. Both work for package installation but conflict if combined. Pick one per environment.
Installing every package globally with
sudo pip install. This pattern is widely warned against. Use a virtual environment instead.
Try It
Exercise: Set up the working environment for the rest of the course:
- Install Python 3.13 or newer. Verify with
python3 --version.- Install VS Code and the Python extension (or configure a preferred editor for Python).
- Create a directory for the course and initialize a virtual environment in it.
- Activate the virtual environment and confirm
which python(macOS/Linux) orwhere python(Windows) points to the venv.- Install a package (
pip install requests) and verify it works (python -c "import requests; print(requests.__version__)").- Create a test file
hello.pycontainingprint("Hello, Python")and run it withpython hello.py.