For Linux/Mac:

1. Move the Script to a Global Directory: Commonly, /usr/local/bin is in the system’s PATH. You can move your script there.

sudo mv <script>.py /usr/local/bin/<script>

2. Make the Script Executable:

sudo chmod +x /usr/local/bin/<script>
 
3.Add a Shebang: At the very top of your Python script, add the following line:
 
#!/usr/bin/env python3
 

This tells the system to use Python to execute the script.

Now, you can simply run <script> from any directory in your terminal.

For Windows:

1.Add Script Directory to PATH:

    • First, place your script in a dedicated directory, e.g., C:\scripts.
    • Then, add this directory to your system’s PATH:
      1. Right-click on ‘This PC’ or ‘Computer’ on the desktop or in File Explorer.
      2. Click on ‘Properties’.
      3. Choose ‘Advanced system settings’ on the left.
      4. Click on the ‘Environment Variables’ button.
      5. In the ‘System Variables’ section, scroll down and select the ‘Path’ variable, then click ‘Edit’.
      6. Click ‘New’, then paste in the path to the directory where your script is located, e.g., C:\scripts.
      7. Click ‘OK’ to close each of the windows.

2.Rename Script for Convenience: Rename your script from <script>.py to <script>.pyw. This will allow you to run the script without popping up a command prompt window.

Now, you can simply run <script>.pyw from any directory in your Command Prompt or PowerShell.

Remember, for the script to work globally, any external Python libraries it uses (like requests) must be installed globally (i.e., they should be accessible from any location on your computer). If you’re using virtual environments, make sure the required libraries are installed in the global environment or in all virtual environments where you plan to use the script.