DOWNLOADING & SETUP PYTHON
To start working with Python, you'll need to download and set up a Python
environment on your system. This involves installing Python, setting up an
Integrated Development Environment (IDE), and optionally managing packages and
virtual environments for different projects. Here’s a step-by-step guide:
1. Download and Install Python
For Windows:
1. Download Python:
o Go to the official Python website.
o Download the latest version of Python for Windows.
o Make sure to select a version that matches your system architecture
(32-bit or 64-bit).
2. Install Python:
o Open the downloaded installer.
o Important: Before clicking "Install Now," check the box that says "Add
Python to PATH". This ensures that Python is accessible from the
command line.
o Click on "Install Now" to start the installation.
o After installation, you can verify the installation by opening Command
Prompt and typing:
python --version
This should display the installed Python version.
For macOS:
1. Download Python:
o Go to the Python download page and download the latest Python
installer for macOS.
2. Install Python:
o Open the downloaded .pkg file and follow the instructions to install
Python.
o To check if Python is installed, open Terminal and run:
python3 --version
o On macOS, Python 2 might be the default version, so you might need
to use python3 instead of python in commands.
For Linux (Ubuntu/Debian):
1. Install Python:
o Python 3 is usually pre-installed on most modern Linux distributions.
To verify, open the Terminal and run:
python3 --version
o If Python 3 is not installed, you can install it using the package
manager:
sudo apt update
sudo apt install python3 python3-pip
2. Install pip (Python's package manager, for installing libraries):
o If pip (Python package installer) is not installed automatically, you
can install it with:
sudo apt install python3-pip
2. Install an IDE or Code Editor
Next, you'll want to install an IDE or a code editor for writing and managing your
Python code. Some popular options are:
PyCharm (For Professional Development):
Download PyCharm from JetBrains.
Install the Community Edition (free) for general Python development.
Follow the installation instructions for your platform.
After installation, open PyCharm and start a new project. You can specify the
Python interpreter when creating a project.
VS Code (Lightweight and Customizable):
Download Visual Studio Code from the official website.
Install the Python extension from the Extensions Marketplace inside VS
Code.
After installation, open VS Code and create a new Python file (.py). It will
automatically prompt you to select a Python interpreter.
Jupyter Notebooks (For Data Science):
Install Jupyter by running the following command in your terminal or
command prompt:
pip install notebook
Start a notebook by running:
jupyter notebook
This will open a browser window where you can create and run Jupyter
notebooks.
Thonny (Beginner-friendly):
Download and install Thonny from [Link].
Thonny is easy to use and pre-configured for Python beginners.
3. Set Up pip (Python's Package Manager)
pip is used to install Python libraries and packages. If it wasn’t installed
automatically during the Python installation, you can install it separately:
Windows/Mac/Linux:
python3 -m ensurepip --upgrade
Once installed, you can use pip to install packages like this:
pip install package-name
For example, to install the requests library:
pip install requests
4. Set Up a Virtual Environment
A virtual environment isolates dependencies for different projects, preventing
conflicts between packages. Here’s how to set up and activate a virtual environment:
Step 1: Install virtualenv (if it's not installed):
pip install virtualenv
Step 2: Create a Virtual Environment:
In the project folder, run the following command to create a virtual environment:
python -m venv myenv
Here, myenv is the name of the virtual environment.
Step 3: Activate the Virtual Environment:
Windows:
myenv\Scripts\activate
macOS/Linux:
source myenv/bin/activate
Once activated, you’ll see (myenv) in your terminal, indicating that the
environment is active. You can now install packages specific to this environment.
To deactivate the virtual environment, simply run:
deactivate
5. Test Your Python Environment
To verify that everything is set up correctly, create a Python file ([Link]) and
write a simple script:
print("Hello, Python!")
Run the file using your terminal or command prompt:
python [Link]
If everything is set up properly, you should see the output: Hello, Python!
6. Install Common Python Libraries
For data science, web development, or automation, you might want to install some
popular Python libraries:
For Data Science:
pip install numpy pandas matplotlib scikit-learn
For Web Development:
pip install django flask
For Automation:
pip install selenium requests beautifulsoup4
Conclusion
After following these steps, you'll have a fully set-up Python environment with the
necessary tools to begin coding. Depending on your specific needs—whether you're
developing software, working with data science, or automating tasks—you can
further customize your environment by installing relevant libraries or IDE
extensions.