StudyLover
  • Home
  • Study Zone
  • Profiles
  • Typing Tutor
  • Contact us
  • Sign in
StudyLover Installing and working with Python
Download
  1. Python
  2. Pyhton MCA (Machine Learning using Python)
  3. Unit 3: Getting Started with Python: A Guide to Syntax, Data Structures, and OOP
Datatypes
Unit 3: Getting Started with Python: A Guide to Syntax, Data Structures, and OOP


1. Installing Python on Windows 🖥️

The most straightforward way to install Python on Windows is by using the official installer from the Python website.

  • Step 1: Download the Installer

    • Go to the official Python website: python.org.

    • The homepage will automatically detect that you're on Windows and show a button to download the latest stable version. Click it to download the installer file (it will be an .exe file).

  • Step 2: Run the Installer

    • Open the downloaded .exe file.

    • Crucial Step: On the first screen of the installer, make sure you check the box at the bottom that says "Add Python to PATH" or "Add python.exe to PATH". This allows you to run Python from the command prompt easily.

    • Click "Install Now" and follow the on-screen instructions. The installer will handle everything else.

  • Step 3: Verify the Installation

    • Once the installation is complete, open the Command Prompt (you can find it by searching for "cmd" in the Start Menu).

    • Type the following command and press Enter:

Bash

python --version

    • If the installation was successful, it will display the Python version you installed (e.g., Python 3.12.4).


2. Installing Python on macOS 🍎

Modern versions of macOS come with a version of Python pre-installed, but it's often an older version. It's highly recommended to install the latest version from the official website.

  • Step 1: Download the Installer

    • Go to the official Python website: python.org.

    • The homepage will detect that you're on macOS and show a download button for the latest version. Click it to download the installer (it will be a .pkg file).

  • Step 2: Run the Installer

    • Open the downloaded .pkg file.

    • Follow the on-screen instructions. It's a standard macOS installation process, so you can generally accept the default settings.

  • Step 3: Verify the Installation

    • Open the Terminal app (you can find it in Applications > Utilities or by searching for it).

    • Type the following command and press Enter:

Bash

python3 --version

    • Note: On macOS and Linux, you often need to use the command python3 (with a '3') to specify that you want to use the version you just installed, as python might still refer to the older, pre-installed version. The command should display the new version number.


3. Installing Python on Linux (Ubuntu/Debian) 🐧

Most Linux distributions come with Python pre-installed. However, you can ensure you have the latest version using the system's package manager.

  • Step 1: Open the Terminal

    • You can usually open the terminal by pressing Ctrl + Alt + T.

  • Step 2: Update Your Package Manager

    • It's always a good practice to update your package list before installing new software. Run the following command:

Bash

sudo apt update

  • Step 3: Install Python

    • Run the following command to install the latest version of Python 3:

Bash

sudo apt install python3

  • Step 4: Verify the Installation

    • In the terminal, type the following command:

Bash

python3 --version

    • This will show you the installed version of Python.


4. Working with Python (All Operating Systems)

Once Python is installed, the workflow is very similar across all systems.

  • Installing Packages with pip

    • Python comes with a package manager called pip. You use it to install external libraries (packages) that provide additional functionality.

    • To install a package, you use the command pip install. For example, to install the popular data analysis library Pandas, you would run:

Bash

pip install pandas

    • On macOS and Linux, you may need to use pip3:

Bash

pip3 install pandas

  • Writing Your First Script

1.   Open any plain text editor (like Notepad, TextEdit, or a code editor like VS Code).

2.   Type a simple Python command:

Python

print("Hello, World!")

3.   Save the file with a .py extension. For example, save it as hello.py on your Desktop.

  • Running Your Script from the Terminal

1.   Open your terminal or command prompt.

2.   Navigate to the directory where you saved your file. The command to change directories is cd. For example, if you saved it on your Desktop, you would type:

Bash

cd Desktop

3.   Run the script by typing python (or python3) followed by the filename:

Bash

python hello.py

4.   You should see the output Hello, World! printed in your terminal.

 

 

Datatypes
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website