A CLI is a text-based way to interact with your computer. Instead of clicking on icons (a GUI - Graphical User Interface), you type commands to perform tasks.
Pro Tip: Drag the Terminal icon from your Applications folder to your Dock for easy access!
The first thing you need to know is your "current working directory".
macOS/Linux: Use the pwd command (Print Working Directory).
Windows: The path is always displayed in the prompt. To list the contents of the directory, use dir.
To see what files and folders are in your current location, use ls (macOS) or dir (Windows).
# macOS / Linux
$ pwd
/Users/your_username
$ ls
Desktop Documents Downloads
# Windows
C:\Users\YourUser> dir
Volume in drive C has no label.
Directory of C:\Users\YourUser
01/01/2023 12:00 PM <DIR> .
01/01/2023 12:00 PM <DIR> ..
01/01/2023 12:00 PM <DIR> Desktop
01/01/2023 12:00 PM <DIR> Documents
The cd (Change Directory) command lets you move around your file system. It works almost identically on both systems.
cd [folder_name]: Move into a folder.cd ..: Move up one level (to the parent folder).cd (Mac) or cd %userprofile% (Win): Go back to your home directory.Tip: Use the Tab key to autocomplete folder and file names!
# Move into the Desktop folder
$ cd Desktop
# Move back up to the home folder
$ cd ..
# --- On Windows ---
C:\Users\YourUser> cd Desktop
C:\Users\YourUser\Desktop>
C:\Users\YourUser\Desktop> cd ..
C:\Users\YourUser>
You can create new directories (folders) and empty files directly from the command line.
To make a folder: The mkdir (Make Directory) command works on both systems.
To make a file: macOS has a simple touch command. The Windows equivalent is a bit more complex.
# --- Both Systems ---
# Create a new folder named 'my-project'
$ mkdir my-project
# --- macOS / Linux ---
# Create an empty file named 'script.py'
$ touch script.py
# --- Windows ---
# Create an empty file named 'script.py'
C:\> type nul > script.py
The mv (move) command on macOS and move on Windows are used to relocate files or folders. You can also use them to rename things!
To Move: Provide the source file and the destination folder.
To Rename: Use the same command, but make the "destination" a new name in the same folder.
# --- macOS / Linux ---
# Move report.txt into the 'Documents' folder
$ mv report.txt Documents/
# Rename 'old_name.txt' to 'new_name.txt'
$ mv old_name.txt new_name.txt
# --- Windows ---
# Move report.txt into the 'Documents' folder
C:\> move report.txt Documents\
# Rename 'old_name.txt' to 'new_name.txt'
C:\> ren old_name.txt new_name.txt
To duplicate a file, you use the copy command.
macOS/Linux: The command is cp (copy).
Windows: The command is copy.
The syntax is cp [source] [destination]. The destination can be a new file name or a folder path.
# --- macOS / Linux ---
# Create a backup of config.txt
$ cp config.txt config.bak
# Copy app.py into the 'archive' folder
$ cp app.py archive/
# --- Windows ---
# Create a backup of config.txt
C:\> copy config.txt config.bak
# Copy app.py into the 'archive' folder
C:\> copy app.py archive\
!!! WARNING !!!
These commands are permanent. They DO NOT move items to the Trash or Recycle Bin.
To delete a file: Use rm on macOS or del on Windows.
To delete an empty folder: Use rmdir on both.
To delete a folder and all its contents: Use rm -r on macOS or rmdir /s /q on Windows. Be extremely careful with this!
# --- macOS / Linux ---
# Delete a single file
$ rm temp_file.txt
# Delete a folder and everything inside it
$ rm -r old-project/
# --- Windows ---
# Delete a single file
C:\> del temp_file.txt
# Delete a folder and everything inside it
C:\> rmdir /s /q old-project\
Let's use our new skills to set up a project structure. Follow the commands for your system.
A virtual environment is a self-contained location or directory that allows you to maintain separate and isolated environments for your Python projects.
This isolation is crucial for managing dependencies, package versions, and even Python versions without conflicts across different projects.
Think of it as giving each project its own clean workspace.
Without them, all your packages are installed globally, which can lead to major problems:
Installing one will break the other. Virtual environments solve this by giving each project its own set of installed packages, completely separate from others.
While Python has a built-in tool (`venv`), the presenter strongly recommends Anaconda.
During the Anaconda installation process, you will see an option:
"Add Anaconda to my PATH environment variable"
Although the installer marks this as "not recommended", you should check this box.
This allows you to run `conda` commands from any terminal, which is essential for a smooth workflow.
After installation, you can verify that Anaconda was correctly added to your PATH.
Open a new terminal (Command Prompt, PowerShell, etc.) and type the following command:
conda
If you see a list of available commands and options, your setup is correct!
# If successful, you'll see output like this:
usage: conda [-h] [-V] command ...
conda is a tool for managing and deploying applications...
options:
-h, --help Show this help message and exit.
-V, --version Show conda version number and exit.
...and so on
A common issue is having multiple standalone Python versions installed from python.org. This leads to confusion about where packages are being installed.
Recommendation: Uninstall all other Python versions from your system.
Let Anaconda manage your Python interpreters. By default, it provides a "base" environment. This simplifies your setup and prevents packages from being installed in the wrong place.
To create a new, isolated environment for a project, use the `conda create` command.
You must specify a name and the Python version you want to use.
For example, to create an environment named `my_project` with Python 3.9:
# The format is:
# conda create --name [env_name] python=[version]
# Example:
conda create --name my_project python=3.9
Once an environment is created, you must "activate" it to use it. This tells your terminal to use the Python and packages from that specific environment.
Your terminal prompt will change to show the active environment's name.
When you're done, you can deactivate it to return to the base environment.
# To activate an environment
conda activate my_project
# Your prompt will now look like:
# (my_project) C:\Users\YourUser>
# To deactivate
conda deactivate
Here are two other essential commands for managing your environments.
List all environments: To see every conda environment you have created on your system.
Remove an environment: To delete an environment and all its packages (be careful!).
# List all environments
conda info --envs
# Remove a specific environment
# The format is:
# conda env remove -n [env_name]
conda env remove -n my_project
If you prefer not to use Anaconda, Python comes with its own built-in module for creating virtual environments called `venv`.
It's lighter than Anaconda but only manages package dependencies, not Python versions themselves.
It's a perfectly valid and very common choice for many developers.
First, navigate your terminal to your project folder.
Then, use the `venv` module to create an environment. It's common practice to name the environment folder `env` or `venv`.
The command differs slightly between operating systems.
# For Windows:
python -m venv env
# For Mac or Linux:
python3 -m venv env
Activating a `venv` environment involves running a script located inside the environment folder.
The path to this script is different for Windows versus Mac/Linux.
Once activated, you will see the `(env)` prefix in your terminal.
# For Windows (in Command Prompt):
env\Scripts\activate.bat
# For Mac or Linux:
source env/bin/activate
Regardless of your operating system or which tool (`conda` or `venv`) you used, deactivating is always the same simple command.
This will return you to your system's default Python environment.
# Universal command to deactivate
deactivate
Once your environment is active, you use `pip` (Python's package installer) to manage libraries.
`pip list` shows all packages installed in the *current active environment*.
`pip install` adds a new package to the active environment.
# List installed packages
pip list
# Install the 'requests' library
pip install requests
# On Mac/Linux, you might need pip3
pip3 install requests
How do you share your project with others so they can easily install the correct dependencies?
You don't send them the whole virtual environment folder. Instead, you create a `requirements.txt` file.
This is a standard text file that lists all the packages and their specific versions needed to run your project.
`pip freeze` generates the list of installed packages in the correct format.
You can redirect this output to a file named `requirements.txt`.
Another user can then install all packages from this file with a single command.
# To create the file:
pip freeze > requirements.txt
# To install from the file in a new environment:
pip install -r requirements.txt
The presenter's strong recommendation for a code editor is Visual Studio Code (VS Code).
The first and most important step after installing VS Code is to install the official Python extension.
This extension provides syntax highlighting, debugging, linting, and interpreter selection.
You need to tell VS Code which Python interpreter to use (e.g., from your conda or venv environment).
The selected interpreter will be shown in the bottom status bar.
Of all the tools and settings discussed, the most important concept is to understand Python interpreters and virtual environments.
Knowing how to create, activate, and manage isolated environments will prevent the most common and frustrating problems that new Python developers face, such as installing packages into the wrong place or dealing with dependency conflicts.
Master this, and your development experience will be much smoother.