Skip to content

Chapter 0: Environment Setup and Development Tools (macOS, Anaconda)

Updated: 2026-09-08 19:10 · English
Table of contents (10)

Language / 语言: English | 中文版

We use two software packages in this course:

  1. Anaconda: Provides the Python runtime environment and the Conda package manager.
  2. Visual Studio Code (VS Code): A code editor used to write and edit programs.

Version Note (2026-09-08): Current macOS installers for Anaconda Distribution target Apple silicon, requiring macOS 12.1 or newer. Intel Mac users can select older releases from the official archive; the 2025.06 release series is the final distribution supporting Intel Macs. Check the system requirements and release notes before installing.

Version numbers shown here illustrate output formats; actual numbers may vary. Software menus and button labels may also change over time. Windows users should read the Windows version (Anaconda). If you prefer a lightweight, standard Python setup, read the macOS version (Standard Python).

This chapter covers downloading, installing, and configuring both tools on macOS, followed by writing and running your first Python program. After running the program successfully, we examine how these tools work together.


Part 1: Core Track

0.1 Install Anaconda

0.1.1 Identify Chip Type and System Version

Apple computers use two processor architectures. Check your computer hardware before downloading:

  1. Click the Apple menu () in the top-left corner of the screen.
  2. Select About This Mac.
  3. Record the macOS version, then check the "Chip" or "Processor" line:
    • If "Chip" lists an Apple M-series processor, your computer uses Apple silicon.
    • If "Processor" lists an Intel Core i5 / i7, your computer uses an Intel chip.

Once you know your processor type, proceed with the matching download.

0.1.2 Download the Installer

  1. For Apple silicon, visit the Anaconda download page and select the Apple silicon Graphical Installer. The filename contains MacOSX-arm64.pkg.
  2. For an Intel Mac, visit the official archive and locate an installer containing MacOSX-x86_64.pkg. Choose a version compatible with your macOS release by consulting the legacy OS installation notes and release notes.
  3. If prompted to register, click Skip registration to view the download links.
  4. Record the installer filename. Note the distinction between .pkg graphical installers and .sh shell scripts; use the .pkg installer here.

0.1.3 Installation Steps

Open Finder, locate the .pkg file in Downloads, double-click it, and follow the installation wizard:

  1. Permission Prompt: If the system displays a dialog stating that the package will run a program to determine if software can be installed, click Allow or Continue.
  2. Introduction: Click Continue.
  3. License Agreement: Read the agreement, click Continue, and then click Agree.
  4. Select Installation Type:
    • Review the installation destination offered by the installer. Note the exact path and click Continue. This path will be needed when configuring the interpreter or diagnosing environment issues.
  5. Start Installation:
    • Click Install.
    • Enter your Mac login password or touch Touch ID to authorize the installation.
  6. Wait for Completion: Installation time depends on your computer hardware. When the installer reports success, click Close.
  7. Clean Up: When asked whether to move the installer to the Trash, click Move to Trash to free disk space.

0.1.4 Verify the Installation

After installation, verify that Conda and Python run correctly:

Example: Inspect the installed Conda and Python version numbers using the macOS terminal.

  1. Press Cmd + Space to open Spotlight Search.
  2. Type Terminal and press Enter to open the terminal window.
  3. At the prompt, enter the following command and press Enter:
    bash
    conda --version
    
    If the output displays a version string like conda 24.x.x, Conda is ready.
  4. Enter the next command and press Enter:
    bash
    python --version
    
    If the output displays a version string like Python 3.12.x, Python is installed correctly. You can now close the terminal window.

0.2 Install Visual Studio Code

0.2.1 Download the Installer

  1. Visit the VS Code download page and check the macOS requirements.
  2. Choose Apple silicon or Intel chip based on your computer hardware, or choose Universal to support both.
  3. Download the .dmg disk image file.

0.2.2 Move VS Code to the Applications Folder

Example: Install VS Code and launch the editor from the Applications folder.

  1. Double-click the .dmg file in your Downloads folder.
  2. In the disk image window, drag Visual Studio Code.app into the Applications folder.
  3. Open VS Code from the Applications folder.

These steps apply to current .dmg installers. If you downloaded a .zip archive, decompress it first, then drag the application to Applications. See the VS Code macOS setup guide.

0.2.3 First Launch

  1. Open Finder, go to the Applications folder, and double-click Visual Studio Code (or open it from Launchpad).
  2. On first launch, macOS displays a confirmation dialog stating that Visual Studio Code was downloaded from the internet. Click Open to proceed to the main window.

0.3 Initial VS Code Setup

A fresh VS Code installation uses English by default and needs the Python extension. Complete these three configuration steps:

0.3.1 Install Language Pack (Optional)

If you prefer an interface language other than English (such as Simplified Chinese):

  1. Open VS Code and click the four-square icon in the left activity bar (Extensions, shortcut: Cmd + Shift + X).
  2. Type Chinese (or your preferred language) in the search box.
  3. Find the official language pack published by Microsoft (such as Chinese (Simplified) Language Pack for Visual Studio Code).
  4. Click Install.
  5. When prompted in the lower-right corner to "Change Language and Restart", click the button to restart VS Code with the new language.

0.3.2 Install the Python Extension

  1. Click the Extensions icon in the left activity bar (or press Cmd + Shift + X).
  2. In the search box, enter Python.
  3. Locate the official Python extension published by Microsoft (marked with the blue and yellow Python logo).
  4. Click Install and wait for the installation to finish.

0.3.3 Select the Anaconda Python Interpreter

Connect VS Code to the newly installed Anaconda environment:

  1. Press Cmd + Shift + P (or choose "View" -> "Command Palette..." from the top menu) to open the command palette.
  2. Type Python: Select Interpreter and select the matching command.
  3. VS Code displays the detected Python environments. Select the entry labeled with conda or base (typically pointing to /opt/anaconda3/bin/python or ~/anaconda3/bin/python).
  4. After selection, the bottom status bar displays the active environment name, such as Python 3.12.x ('base': conda).

0.4 Write and Run Your First Program

Next, create a dedicated project folder, then save and run your first program.

0.4.1 Create a Working Directory

Keep your course programs in a single folder for organized access.

Example: Create a python_code folder in Documents and open it in VS Code.

  1. Open Finder and click Documents in the left sidebar.
  2. Right-click an empty area (or hold Control and click), select "New Folder", and name it python_code.
  3. In VS Code, select File -> Open Folder... from the top menu (shortcut: Cmd + O).
  4. Select the python_code folder and click Open.
  5. When prompted with the dialog asking "Do you trust the authors of the files in this folder?", click Yes, I trust the authors.

0.4.2 Create a Source File

  1. In the VS Code Explorer sidebar on the left, locate the PYTHON_CODE folder header.
  2. Hover over the folder name and click the New File icon (a file icon with a plus sign).
  3. Type the filename hello.py and press Enter. (Python source files use the .py extension.)
  4. An empty editor tab for hello.py opens.

0.4.3 Write and Execute the Code

In the hello.py editor tab, type this line:

Example: Run one line of code to print Hello, world! to the terminal.

python
print("Hello, world!")

Press Cmd + S to save the file. (An unsaved file shows a solid dot next to its filename; saving removes the dot.)

Running the Program (Choose Either Method):

  • Method 1 (Recommended): Click the triangular Play button in the upper-right corner of the editor (tooltip: "Run Python File in Dedicated Terminal").
  • Method 2: Right-click anywhere in the code editor and choose "Run Python File in Terminal".

VS Code opens an integrated terminal panel at the bottom and prints the output:

text
Hello, world!

Seeing this text confirms that the Python interpreter executed hello.py successfully. Replace the text inside the quotes with your name, run the file again, and observe the new output.


0.5 Understanding the Tools

0.5.1 The Python Interpreter and Anaconda

The Python interpreter reads and executes Python code. When you ran hello.py, the interpreter executed the print(...) statement and wrote text to the terminal.

Anaconda provides Python together with a collection of standard packages. This chapter uses the Python environment included in Anaconda. Conda manages packages and virtual environments, allowing you to install additional libraries when needed.

0.5.2 VS Code

VS Code is a code editor. It highlights syntax, suggests autocompletions, and hosts an integrated terminal in one window. With the Python extension installed, it detects interpreters and executes .py files.

0.5.3 From Source File to Program Output

  1. Save hello.py in VS Code.
  2. Trigger "Run Python File in Terminal".
  3. The selected Python interpreter executes the file.
  4. The terminal displays the printed results.

Writing code and running code are separate steps. Knowing which file and which interpreter you are running makes it easier to diagnose issues, such as code changes that do not seem to take effect or packages that cannot be found.


Part 2: Supplementary Notes

0.6 Troubleshooting Common Issues (FAQ)

0.6.1 Terminal Message: zsh: command not found: conda

This message indicates that the shell cannot locate the conda command. Review the installation directory recorded during setup to identify where Anaconda is installed.

Example: Activate an Anaconda installation at /opt/anaconda3 and initialize Conda for future zsh sessions.

bash
source /opt/anaconda3/bin/activate
conda init zsh

The path /opt/anaconda3 is an example. If Anaconda is installed in ~/anaconda3 or another directory, replace the first line with the actual path to bin/activate. Close and reopen the terminal, then run conda --version to verify. If errors persist, consult the Anaconda troubleshooting guide.

0.6.2 Missing Run Button or Unselected Interpreter

  • Symptom: The triangular run button does not appear in the top-right corner, or a prompt says Select an Interpreter.
  • Solution:
    1. Confirm that the filename ends in .py. If saved as text (such as .txt), VS Code will not activate Python tooling.
    2. Press Cmd + Shift + P, type Python: Select Interpreter, and press Enter.
    3. In the list that appears, select the Python path containing conda.

0.7 Productivity Settings

0.7.1 Enabling Auto Save

Saving files with Cmd + S before running them is a good habit. The "Run Python File in Terminal" command in the Python extension also saves the active file before execution, though other launch methods may not. See the official run documentation.

To enable Auto Save in VS Code:

  1. Click File in the top menu bar.
  2. Select Auto Save.
  3. VS Code saves dirty files automatically according to its configuration.

0.7.2 macOS Keyboard Habits

In macOS, keyboard shortcuts differ slightly from Windows:

  • Many shortcuts use the Command key (⌘) on macOS where Windows uses the Ctrl key.
  • The Option key (⌥) is often labeled Alt.

Common VS Code shortcuts on macOS:

Shortcut Description
Cmd + S Save the active file
Cmd + / Toggle single-line comment (adds or removes #)
Cmd + Shift + P Open the Command Palette
Cmd + B Show or hide the primary sidebar
Ctrl + Backtick Show or hide the integrated terminal (uses the Control key)

0.8 Basic Conda Commands

Most course programs run directly from VS Code. If you want to inspect your environment in the terminal, open Terminal and run these commands:

Example: List all packages installed in the active Anaconda environment.

bash
conda list

Common Commands:

  • conda --version: Print the Conda version.
  • conda list: List installed packages and versions.
  • python: Start the interactive Python shell (type exit() to quit).
  • python filename.py: Execute a script file directly.

Self-Check

Record your macOS version, chip type, Anaconda installer filename, and the output of python --version. Review the official documentation to explain why this installer matches your computer architecture. Then modify the printed text in hello.py and run it again.


Navigation: Course overview (Chinese) | Next: Chapter 1 Basic Data Types and Operations (Chinese)

The English version of Chapter 1 is not yet available.