Skip to content

⚙️ Setting Up Your Python Environment

Python Installation

Detailed instructions on how to install Python on various operating systems.

Package Management

Introduction to pip and virtual environments for dependency management.

Development Tools

Overview of popular IDEs, editors, and Git for a productive coding setup.

Python Installation

Before diving into Python coding, it’s essential to set up a proper development environment. This section guides you through the necessary steps, including installing Python, managing packages, and configuring your preferred tools.

The first step is to install Python on your machine. The installation process varies slightly depending on your operating system.

Installation on Windows

  1. Go to the Official Python Website and download the latest version of Python for Windows.
  2. Run the installer. Make sure to check the “Add Python to PATH” option during the installation. This allows you to run Python from the command line.
  3. Complete the installation.
  4. To verify the installation, open the Command Prompt and type python --version. You should see the installed Python version printed on the console.

Installation on macOS

  1. Go to the Official Python Website and download the latest version of Python for macOS.
  2. Run the installer and follow the on-screen instructions.
  3. Verify your installation. Open Terminal and type python3 --version. If you have Python 2.7 installed by default, using python command might give you Python 2.

Installation on Linux

Linux systems may have Python pre-installed, but it’s often an older version. It’s recommended to install the latest version using your distribution’s package manager. Here are examples:

  1. Open a Terminal.
  2. Update the package list using sudo apt update.
  3. Install Python 3 using sudo apt install python3 python3-pip.
  4. Verify the installation with python3 --version and pip3 --version.

Package Managers (pip)

Python has a powerful package manager called pip. It’s used to install and manage external libraries and dependencies needed for your projects.

Installing packages with pip

To install a package, use the pip install command followed by the package name. For example, to install the requests library:

Terminal window
pip install requests

To verify the installation, you can list the installed packages with:

Terminal window
pip list

Virtual Environments

When working on multiple Python projects, each project might require different versions of packages. Using virtual environments isolates the dependencies of each project, preventing conflicts and dependency issues.

Creating a Virtual Environment

  1. Open Terminal or Command Prompt and navigate to your project’s root folder.
  2. Run the command python3 -m venv venv. This creates a directory named venv (you can choose a different name if you wish) that contains the isolated python environment.

Activate the environment:

Use the command source venv/bin/activate in the terminal.

You should now see the environment name (venv) shown on the terminal line. Any packages you install with pip will now be specific to this virtual environment. 4. To deactivate, use the deactivate command in the terminal.

IDEs and Editors

Choosing the right development environment can significantly improve your productivity. Here are some of the most popular IDEs and editors for Python development:

VS Code

  1. Download VS Code for your operating system.
  2. Install the Python extension by Microsoft to have support for linting, debugging, and code formatting.
  3. Install additional extensions to improve your workflow and add extra funcionality as needed.

VS Code is a free, lightweight, and customizable code editor with a wide range of extensions. It is a great all-around option.

PyCharm

  1. Download PyCharm for your operating system.
  2. Install the editor. Choose either the Professional or Community version. The community edition is free but will lack some advanced features.
  3. Configure the Python interpreter to use the one you have installed.

PyCharm is a powerful and specialized IDE designed for Python development. It offers intelligent code completion, debugging tools, and support for web frameworks.

Jupyter Notebook / JupyterLab

  1. Install Jupyter with pip install jupyterlab.
  2. Start Jupyter Lab with the command jupyter lab in the terminal. This will open a browser window.
  3. Start creating your notebooks.

Jupyter Notebook and JupyterLab are excellent for data analysis, visualization, and interactive development. It also allows to write and render markdown documents.

Other Editors

Other options include Sublime Text, Atom, and Vim. Choose the one that fits your workflow and preferences the best.

Basic Git for Development

Git is a version control system that helps track changes in your code and collaborate with others. It is a very important tool that you should learn to use.

  1. Download and install Git from the official website.

  2. Configure git using the following commands in the terminal. These commands only need to be set once for each machine:

    Git Configuration
    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
  3. Initialize a new git repository within your project’s directory:

    Terminal window
    git init
  4. Add your files to staging using:

    Terminal window
    git add .
  5. Commit your changes using:

    Terminal window
    git commit -m "Initial commit"
  6. (Optional) Create an account in Github or a similar git platform and create a new repository. Copy the git repository link and add it to your repository with:

    Terminal window
    git remote add origin your_repository_link
  7. Finally, push your repository to your remote repository:

    Terminal window
    git push -u origin main

It’s crucial to commit your changes regularly, use descriptive commit messages, and utilize branching for feature development.

Download Python

pip Documentation

VS Code Website

Official Git Website