> For the complete documentation index, see [llms.txt](https://swimplify.gitbook.io/python-virtual-environment/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://swimplify.gitbook.io/python-virtual-environment/setting-up-your-python-playground.md).

# Setting Up Your Python Playground

<figure><img src="/files/6F6D2OWwcPK3pgE4FZaf" alt=""><figcaption></figcaption></figure>

Welcome to our inaugural quick code guide! Today, we're diving into a fundamental skill for Python developers - setting up a virtual environment.

Picture this: Your own dedicated space, free from the clutter of conflicting packages, where you can experiment, create, and innovate with Python. That's exactly what a virtual environment offers. It's like having your very own laboratory, tailor-made for Python projects.

In this step-by-step guide, we'll walk you through the process of creating a virtual environment, enabling you to work on multiple projects with different dependencies, without any interference. Whether you're a beginner or a seasoned developer, mastering this skill is essential for efficient Python programming.

Ready to unlock the full potential of Python in your projects? Let's get started on this exciting journey!

### Before You Begin: Requirements

Before you dive into this guide, make sure you have the following:

* **Python Installed:** Ensure you have Python installed on your system. You can download it from the official [python](https://www.python.org/) website.
* **Terminal or Command Prompt:** Familiarize yourself with your system's terminal or command prompt. This guide assumes you have a basic understanding of using the command line.
* **Text Editor:** Have a text editor of your choice installed for writing and editing Python code. Popular choices include Visual Studio Code, Sublime Text, or Atom.
* **A Sense of Adventure:** Approach this guide with curiosity and a willingness to explore. Coding is an adventure, and every challenge is an opportunity to learn!

## Choose Your Python Playground

Open your terminal and navigate to the directory where you're going to create your Python project. Create a folder by runing the command:

{% tabs %}
{% tab title="Unix/macOS" %}

```bash
mkdir python_project
```

{% endtab %}

{% tab title="Windows" %}

```bash
mkdir python_project
```

{% endtab %}
{% endtabs %}

## Step Inside Your New Space

Step into your freshly minted folder:

{% tabs %}
{% tab title="Unix/macOS" %}

```bash
cd python_project
```

{% endtab %}

{% tab title="Windows" %}

```powershell
cd python_project
```

{% endtab %}
{% endtabs %}

## Time to Build Your Digital Fort

It's time to create a secret hideout, known as a virtual environment, for your Python adventures. Depeding on the python version you have installed on your machine, execute:

{% tabs %}
{% tab title="Unix/macOS" %}

```bash
python -m venv .venv
```

{% endtab %}

{% tab title="Windows" %}

```powershell
py -m venv .venv
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The dot at the beginning of .venv makes this folder magically hidden!, which is a good practice.
{% endhint %}

## Activate Your Virtual Adventure Zone

Activate your virtual environment to start your coding journey in isolation. Run the following command:

{% tabs %}
{% tab title="Unix/macOS" %}

```bash
source .venv/bin/activate
```

{% endtab %}

{% tab title="Windows" %}

```powershell
.venv\Scripts\activate
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
You will notice that your comand line will start with (.venv) which means you are currently working inside a virtual environment.
{% endhint %}

## Exit Your Coding Oasis

When you're done for the day, deactivate your virtual environment. You'll know it's done when (.venv) disappears from your terminal, run the comand:

```bash
deactivate
```
