Skip to content

Latest commit

 

History

History
108 lines (77 loc) · 2.86 KB

File metadata and controls

108 lines (77 loc) · 2.86 KB

How to Install Python on Windows, Linux, and macOS

Windows

  1. Download the Installer:

    • Go to the official Python website: python.org.
    • Navigate to the "Downloads" tab and click on "Python 3.x.x" (where "x.x" is the latest version number).
  2. Run the Installer:

    • Once the installer is downloaded, run it.
    • Make sure to check the box that says "Add Python 3.x to PATH" before clicking "Install Now".
  3. Verify Installation:

    • Open Command Prompt by pressing Win + R, typing cmd, and pressing Enter.
    • Type python --version and press Enter to verify the installation.

Linux (Ubuntu/Debian)

  1. Update Package List:

    • Open a terminal and run:
      sudo apt update
  2. Install Python:

    • Run the following command to install Python 3:
      sudo apt install python3
  3. Verify Installation:

    • Type python3 --version in the terminal to verify the installation.

macOS

  1. Install Homebrew (if not already installed):

    • Open a terminal and run:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Python:

    • Once Homebrew is installed, run:
      brew install python
  3. Verify Installation:

    • Type python3 --version in the terminal to verify the installation.

Virtual Environment Installation

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated environments for them. This is particularly useful when you have projects that rely on different versions of the same package.

1. Open Your Terminal or Command Prompt

  • On Windows, you can use Command Prompt or PowerShell.
  • On macOS and Linux, you can use Terminal.

2. Create a Directory for Your Project

Navigate to the directory where you want to create your project and create a new directory for it.

mkdir my_project
cd my_project

3. reate a Virtual Environment

Use the venv module to create a virtual environment. Replace myenv with the name you want for your virtual environment.

python -m venv myenv

4. Activate the Virtual Environment

On Windows:

myenv\Scripts\activate

On macOS and Linux:

source myenv/bin/activate

5. Verify the Virtual Environment is Active

Once activated, your terminal prompt should change to show the name of the virtual environment. For example:

(myenv) user@hostname:~/my_project$

6. Install Packages in the Virtual Environment

You can now install packages using pip without affecting the global Python installation.

pip install <package_name>

7. Deactivate the Virtual Environment

When you're done working in the virtual environment, you can deactivate it by simply running:

deactivate