Chuyển tới nội dung chính

Python Installation

I. Why Python?​

1/ What is it​

  • a beginner-friendly language with a really clean syntax, and it's everywhere: data, AI/ML, automation, web,...
  • pip comes with it, it's the tool to install libraries (numpy, pandas,...)
  • most of the Documents section (python tutorials, data analysis) runs on it

2/ Which version?​

  • just take the latest Python 3 release (3.x.x)
  • if a course / project asks for a specific version (e.g. 3.11), install that one instead

II. Installing Python​

1/ Download​

2/ Run the installer​

  • open the file u just downloaded
  • super important: on the first screen, tick "Add python.exe to PATH" (bottom of the window). if u forget it, the terminal won't recognize python
  • then click on Install Now and wait
  • at the end, if u see Disable path length limit, click it too (avoids errors with long file paths later), then Close

3/ Check python & pip​

  • open Command Prompt (Windows -> cmd -> Enter)
  • paste these in and press Enter:
python --version
pip --version
  • if the output is, for example, Python 3.x.x and pip 2x.x ... then ure done
  • py --version works too, py is the python launcher for windows

III. Python in VS Code​

1/ Python extension​

  • Visual Studio Code -> Ctrl + Shift + X (Extensions)
  • search for Python and install Python (Microsoft, the one with millions of downloads). it comes with Pylance (autocomplete, error hints)

2/ Select the interpreter​

  • Ctrl + Shift + P -> type Python: Select Interpreter -> choose the version u installed
  • u can see / change it later at the bottom right corner of VS Code

3/ First script​

  • create a file hello.py:
hello.py
name = "mathalgo"
print(f"hello from {name}")
  • run it with the ▷ on the top right, or in the terminal (Ctrl + `):
python hello.py

IV. pip & virtual environments​

1/ Installing libraries​

pip install numpy
pip list

2/ venv (one environment per project)​

  • each project gets its own libraries -> no version fights between projects
  • inside ur project folder:
python -m venv .venv
.venv\Scripts\activate
  • now the terminal starts with (.venv), everything u pip install stays inside this project. type deactivate to get out
  • in VS Code, pick .venv as the interpreter (step III.2)

V. Common errors​

  • typing python opens the Microsoft Store: windows has a fake "python" shortcut. go to Settings > Apps > Advanced app settings > App execution aliases, turn off python.exe and python3.exe, then reopen the terminal
  • 'python' is not recognized as an internal or external command: "Add python.exe to PATH" wasn't ticked. run the installer again -> Modify -> Next -> tick Add Python to environment variables (or just uninstall and install again with the box ticked)
  • pip not recognized but python works: use python -m pip install ... instead
  • running scripts is disabled on this system when activating the venv (PowerShell): run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once, or just use Command Prompt
  • about the Python install manager: it's on python.org (yellow button) and the Microsoft Store, and uses the py command to install / switch versions (py install 3.14, py list). the standalone installer stops being released from Python 3.16, so u'll probably move to it later

So overall: tick "Add python.exe to PATH", check with python --version, one venv per project​


VI. Reference Sources​

  • Python Docs. Using Python on Windows. docs.python.org
  • Visual Studio Code Docs. Python in Visual Studio Code. code.visualstudio.com