Setting Up Python on Windows/Linux¶
Introduction¶
Python is a powerful, versatile programming language that's widely used for various applications, from web development to data science. This guide will help you set up Python on both Windows and Linux systems.
Setting Up Python on Windows¶
Step 1: Download Python Installer¶
- Go to the official Python website.
- Click on the Downloads section.
- Download the latest Python installer for Windows.
Step 2: Run the Installer¶
- Open the downloaded installer.
- Check the box that says "Add Python to PATH". This is crucial for running Python from the command line.
- Click on "Install Now".
- Once the installation is complete, click "Close".
Step 3: Verify the Installation¶
- Open Command Prompt.
- Type
python --versionand press Enter. You should see the installed Python version. - Similarly, type
pip --versionto verify that pip (Python's package installer) is also installed.
Step 4: Install a Code Editor (Optional)¶
- Download and install a code editor like Visual Studio Code or PyCharm.
Setting Up Python on Linux¶
Step 1: Update Package List¶
Open a terminal and run the following command to update your package list:
sudo apt update
Step 2: Install Python¶
Most Linux distributions come with Python pre-installed. To check if Python is installed, run:
python3 --version
If Python is not installed, you can install it using:
sudo apt install python3
Step 3: Verify the Installation¶
To verify the installation, run:
python3 --version
You should see the installed Python version.
Step 4: Install pip¶
If pip is not installed by default, install it using:
sudo apt install python3-pip
Verify the installation with:
pip3 --version
Step 5: Install a Code Editor (Optional)¶
You can install a code editor like Visual Studio Code or PyCharm. For Visual Studio Code, use:
sudo snap install --classic code
Creating a Virtual Environment¶
A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages.
Windows¶
- Open Command Prompt.
- Navigate to your project directory.
- Run the following command to create a virtual environment:
python -m venv myenv - Activate the virtual environment:
myenv\Scripts\activate
Linux¶
- Open a terminal.
- Navigate to your project directory.
- Run the following command to create a virtual environment:
python3 -m venv myenv - Activate the virtual environment:
source myenv/bin/activate
Installing Packages¶
Once the virtual environment is activated, you can install packages using pip.
Example¶
To install the requests package, run:
pip install requests
Conclusion¶
You've successfully set up Python on your Windows or Linux system. You can now start developing Python applications and using various packages to enhance your projects.
![]()