Installing Python and Setting Up Your First Project

Installing Python and Setting Up Your First Project


Step 1: Download and Install Python


Visit the Official Python Website


Go to https://www.python


Download the latest stable version for your operating system (Windows, macOS, or Linux).


Install Python


Run the installer and ensure you check the box that says "Add Python to PATH" before clicking Install.


Follow the installation prompts and complete the setup.


Verify Installation


Open a terminal (Command Prompt, PowerShell, or Terminal on macOS/Linux) and run:


python --version


If Python is installed correctly, it will display the version number.


Step 2: Set Up a Virtual Environment


Create a Project Directory


Open a terminal and navigate to the location where you want your project.


Run:


mkdir my_project

cd my_project


Create a Virtual Environment


Run the following command:


python -m venv venv


This creates a venv folder that contains a separate Python environment for your project.


Activate the Virtual Environment


On Windows:


venv\Scripts\activate


On macOS/Linux:


source venv/bin/activate


Your terminal should now show (venv) before the command prompt, indicating that the virtual environment is active.


Step 3: Install Required Packages


Install Packages Using pip


To install dependencies, use:


pip install package_name


For example, to install requests:


pip install requests


Freeze Dependencies


Save the installed packages to a requirements.txt file:


pip freeze > requirements.txt


Install Dependencies from requirements.txt (if needed later)


Run:


pip install -r requirements.txt


Step 4: Create Your First Python Script


Create a Python File


In your project directory, create a new file named main.py.


Write a Simple Python Script


Open main.py and add the following code:


print("Hello, World!")


Run the Script


In the terminal, run:


python main.py


You should see Hello, World! printed on the screen.


Step 5: Deactivate the Virtual Environment (Optional)


To exit the virtual environment, simply run:


deactivate


You are now set up with Python and ready to start coding your first project!

Read More

Introduction to Python: Why Learn It?

Visit Our Quality Thought Training in Hyderabad


Nilgiri Block,
H No 7-1-618/NG/302,
Flat No 302, Aditya Enclave,
Ameerpet, Hyderabad, Telangana, 500016.
Land Mark: Beside Ameerpet Metro

Comments

Popular posts from this blog

Understanding Snowflake Editions: Standard, Enterprise, Business Critical

Why Data Science Course?

How To Do Medical Coding Course?