Course
Environment Setup
Python Tutorial
This Python tutorial has been written for the beginners to help them understand the basic to advanced concepts of Python Programming Language. After completing this tutorial, you will find yourself at a great level of expertise in Python, from where you can take yourself to the next levels to become a world class Software Engineer.
Environment Setup
First step in the journey of learning Python is to install it on your machine. Today most computer machines, especially having Linux OS, have Python pre-installed. However, it may not be the latest version.
Python is available on a wide variety of platforms including Linux and Mac OS X. Let's understand how to set up our Python environment.
Windows
- Download Python: Go to the official Python website (python.org) and download the latest version of Python for Windows. Choose the executable installer.
- Install Python:
- Run the downloaded executable.
- Check the box next to "
Add Python X.X to PATH
" at the bottom of the installation window (X.X refers to the version number).
- Click on "Install Now".
- Verify Installation:
- Open Command Prompt (cmd).
- Type
python --version
and press Enter. You should see the Python version number if the installation was successful.
- Install pip (Python's package manager): Pip is included with Python versions 3.4 and later, but if for some reason it's not installed, you can install it by downloading
get-pip.py
from the official pip website and running it using Python.
- Setting up a Virtual Environment:
- In Command Prompt, navigate to your project directory.
- Run
python -m venv myenv
(replace "myenv
" with your desired environment name).
- Activate the environment:On Windows, run
myenv\Scripts\activate
.
macOS
- Install Python:
- Python 2.7 comes pre-installed on macOS, but it's recommended to use Python 3.
- You can install Python 3 via Homebrew (a package manager for macOS). If you don't have Homebrew installed, you can install it by running
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)”
in the Terminal. - After installing Homebrew, run
brew install python
. - Verify Installation:
- Open Terminal and type
python3 --version
to verify Python 3 is installed. - Install pip:
- Pip is included with Python 3 installations from Homebrew.
- Setting up a Virtual Environment:
- In Terminal, navigate to your project directory.
- Run
python3 -m venv myenv
. - Activate the environment by running
source myenv/bin/activate
.
Linux
- Install Python:
- Most Linux distributions come with Python pre-installed. You can verify this by typing
python3 --version
in the Terminal. - If Python is not installed, you can install it using your distribution's package manager. For example, on Ubuntu or Debian, run
sudo apt-get update
followed bysudo apt-get install python3
. - Verify Installation:
- Type
python3 --version
in the Terminal to verify the installation. - Install pip:
- If pip is not installed, you can install it by running
sudo apt-get install python3-pip
(on Ubuntu/Debian). - Setting up a Virtual Environment:
- Navigate to your project directory in the Terminal.
- Run
python3 -m venv myenv
. - Activate the environment by running
source myenv/bin/activate
.
For all systems, once you have your virtual environment activated, you can use
pip
to install Python packages locally within the environment (e.g., pip install package_name
). This setup ensures that your project's dependencies are isolated from the system-wide Python environment.