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).
- 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).
- Python installed on your system.
- For Windows, Git Bash or a similar shell that can execute bash scripts.
-
Download the
setup_env.sh
script. -
Move it to a directory that's in your PATH. For example:
mv setup_env.sh /usr/local/bin/setup_env.sh
-
Make the script executable:
chmod +x /usr/local/bin/setup_env.sh
- Download Git Bash (if not already installed) from Git for Windows.
- Download the
setup_env.sh
script. - 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.
- Make the script executable in Git Bash:
chmod +x /path/to/setup_env.sh
- Navigate to your project directory.
- Run the script:
setup_env.sh
- The script will create a
venv
directory, arequirements.txt
file (if not present), install dependencies, and create anapp.py
file for a Flask project.
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
- The script assumes the use of
python3
on macOS, andpython
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 inapp.py
.
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!