This Bash script automates the setup of a Python virtual environment, installation of dependencies, and updating the requirements.txt file. Additionally, it provides an option to install the dependencies globally and configure the script for global access.
- Navigate to Script Directory: Automatically moves to the directory where the script is located.
- Remove Old Virtual Environment: Deletes any existing Python virtual environment (
venv/) to ensure a fresh setup. - Create a New Virtual Environment: Initializes a new virtual environment in the current directory.
- Activate Virtual Environment: Activates the newly created environment.
- Install Dependencies: Installs required Python packages specified in
requirements.txt. - Update
requirements.txt: After installation, therequirements.txtis updated with the latest installed packages.
-
Clone the repository or download the script.
-
Ensure you have Python 3 installed on your system.
-
Run the script:
./pip-env.sh
This will create a virtual environment, install the dependencies, and activate the environment.
If you prefer to install the dependencies globally and make the script available system-wide, follow these steps:
-
Install Dependencies Globally:
Instead of using a virtual environment, you can install the dependencies globally by running:
pip install -r requirements.txt
-
Add Script to Global PATH:
Add the
bindirectory of this repository to your system'sPATHto run the script globally from anywhere.-
Edit your shell configuration file (e.g.,
~/.bashrc,~/.zshrc) and add the following line:export PATH="/path/to/your/repo/bin:$PATH"
Replace
/path/to/your/repo/binwith the full path to thebindirectory in your repository.
-
-
Reload your shell:
After updating the
PATH, run:source ~/.bashrc # for Bash users source ~/.zshrc # for Zsh users
Now you can run the script globally by simply typing the script name from any location in your terminal.
- Python 3: Ensure that Python 3 is installed.
- boto3: Add
boto3to yourrequirements.txtif not already present.
- This script assumes that
requirements.txtis in the same directory as the script. - For the virtual environment option, the script regenerates the environment each time it is run, deleting the old one.
- For the global installation option, make sure you have the necessary permissions to install global Python packages.
Now you should be able to copy it easily from here!