/python-virtual-env-generator

A simple bash script that sets up your python virtual environment and generates a boilerplate flask app.

Primary LanguageShell

Python Environment Setup Script

Overview

The setup_env.sh script is a convenient tool for Python developers. It automates the process of setting up a new Python virtual environment, installing required packages from requirements.txt, and creating a basic Flask application file (app.py) if it doesn't already exist. This script is compatible with Unix-like systems (macOS and Linux) and Windows (using Git Bash or similar).

Features

  • Automatically creates a Python virtual environment.
  • Installs packages from requirements.txt.
  • Creates a requirements.txt file with essential packages if it doesn't exist.
  • Generates a basic Flask app.py file if not present.
  • Compatible with macOS, Linux, and Windows (Git Bash).

Prerequisites

  • Python installed on your system.
  • For Windows, Git Bash or a similar shell that can execute bash scripts.

Setup Instructions

macOS and Linux

  1. Download the setup_env.sh script.

  2. Move it to a directory that's in your PATH. For example:

         mv setup_env.sh /usr/local/bin/setup_env.sh
  3. Make the script executable:

    chmod +x /usr/local/bin/setup_env.sh

Windows

  1. Download Git Bash (if not already installed) from Git for Windows.
  2. Download the setup_env.sh script.
  3. Move it to a directory that's in your PATH. You can modify your PATH via System Properties or place the script in an existing PATH directory.
  4. Make the script executable in Git Bash:
        chmod +x /path/to/setup_env.sh

Running the Script

  1. Navigate to your project directory.
  2. Run the script:
       setup_env.sh
  1. The script will create a venv directory, a requirements.txt file (if not present), install dependencies, and create an app.py file for a Flask project.

Activating the Virtual Environment

After running the script, activate your virtual environment:

  • On macOS and Linux:
    source venv/bin/activate
  • On Windows (in Git Bash):
    source venv/Scripts/activate

Additional Information

  • The script assumes the use of python3 on macOS, and python on Linux and Windows.
  • For customizing the script, you can edit it to add more packages to requirements.txt or modify the Flask app template in app.py.

Important Note on Safety

⚠️ Caution with Scripts

Running scripts, especially those downloaded from the internet, can pose a security risk to your system. It is crucial to understand the potential dangers:

  • Always Review the Script: Before running any script, especially those that require administrative or elevated privileges, carefully review its contents. Understand what each line of code does.

  • Trust and Source: Only run scripts from trusted sources. If you're unsure about the script's origin or its safety, avoid using it until you can verify its integrity.

  • Modifications: If you're modifying the script, ensure that your changes do not introduce any vulnerabilities or harmful actions.

  • Environment: Consider running scripts in a safe environment, such as a virtual machine or a container, if you are testing scripts from unknown or untrusted sources.

Remember, it's better to be cautious and take the time to understand what a script does before executing it, rather than risking potential harm to your system or data.

Thanks!