How to Install Python on Windows
- Download Python
- Go to the official Python website.
- Click on the “Downloads” tab and choose the version for Windows (e.g., Python 3.x.x).
- Run the Installer
- Open the downloaded
.exefile. - Important: Check the box for “Add Python to PATH” before clicking Install.
- Follow the installation wizard to complete the setup.
- Open the downloaded
- Verify the Installation
- Open the Command Prompt (CMD).
- Type
python --versionorpythonto check the Python version.python --version
- Install Pip (Optional)
- Pip is usually included with Python. Verify it with:
pip --version
How to Install Python on macOS
- Pip is usually included with Python. Verify it with:
- Download Python
- Go to the official Python website.
- Click on the “Downloads” tab and select the macOS installer (
.pkg).
- Run the Installer
- Double-click the downloaded
.pkgfile and follow the installation instructions.
- Double-click the downloaded
- Verify the Installation
- Open Terminal and type:
python3 --version - Use
python3for Python 3.x because macOS might include an older Python 2.x version.
- Open Terminal and type:
- Install Pip (Optional)
- Pip is included with Python 3.x. Confirm by typing:
pip3 --version
How to Install Python on Linux
- Pip is included with Python 3.x. Confirm by typing:
- Check Pre-installed Python
- Most Linux distributions include Python by default. Check with:
python3 --version
- Most Linux distributions include Python by default. Check with:
- Install Python Using a Package Manager
- For Ubuntu/Debian:
sudo apt update sudo apt install python3 python3-pip - For CentOS/Fedora:
sudo yum install python3
- For Ubuntu/Debian:
- Compile Python from Source (Optional)
- If you need the latest Python version, download the source code and compile it:
sudo apt update sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev \ libssl-dev libreadline-dev libffi-dev curl libsqlite3-dev wget wget https://www.python.org/ftp/python/3.x.x/Python-3.x.x.tar.xz tar -xf Python-3.x.x.tar.xz cd Python-3.x.x ./configure --enable-optimizations make sudo make altinstall
- If you need the latest Python version, download the source code and compile it:
- Verify the Installation
- Run:
python3 --version
After Installation: Setting Up a Virtual Environment
It’s a good practice to use virtual environments to manage dependencies for individual projects.
- Run:
- Create a Virtual Environment
- Run:
python3 -m venv myenv
- Run:
- Activate the Virtual Environment
- On Windows:
myenv\Scripts\activate - On macOS/Linux:
source myenv/bin/activate
- On Windows:
- Deactivate the Virtual Environment
- When done, run:
deactivate
- When done, run: