Run Python 3 script with the same command on Windows, Linux, and macOS? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: Run Python 3 script with the same command on Windows, Linux, and macOS? (/thread-30957.html) |
Run Python 3 script with the same command on Windows, Linux, and macOS? - ssrobins - Nov-15-2020 I use Python 3 scripts to automate various steps in continuous integration (CI) in Azure DevOps and GitHub Actions that runs on Windows, Linux, and macOS. I prefer to set it up so one step is shared across all platforms. To do that, I need to be able to run the exact same command to run the Python script on all platforms. Unfortunately, this is surprisingly complicated. Problem 1: There isn't a consistent way to launch Python 3 across all platforms:
Problem 2: Running the script without any sort of python , python3 , and py commands is subject to shell inconsistencies across the platformsOn macOS and Linux, add #!/usr/bin/env python3 to the first line of the script and run chmod +x script.py to make it executable. Even with those changes, we still have these problems:
So as a result of all of this, I can either struggle to get one shell to run on all platforms (either get PowerShell working on macOS and Linux or get bash working on Windows) or give up and set variables to define the Python command differently on Windows versus macOS/Linux (my current workaround). Am I missing an obvious solution that's already available? If not, I think the best solution to this problem would be if py was available on non-Windows platforms. Having python3 available on Windows would be an ok solution too. Is there any reason why it isn't? I'd be happy to play the long game and actually look into contributing such a thing to Python, but I wanted to chat about it and understand it better first. Python is great for this sort of cross-platform automation. Consistent launching of the script would would make it awesome!
RE: Run Python 3 script with the same command on Windows, Linux, and macOS? - buran - Nov-15-2020 Just to be sure you are aware - we are not associated with PSF or python core development team. Check https://python-forum.io/misc.php?action=help&hid=48 Otherwise you are welcome to discuss any python-related topics with the community here. RE: Run Python 3 script with the same command on Windows, Linux, and macOS? - ssrobins - Nov-15-2020 I am aware, thanks. I figured this would be a good first step before trying to engage more officially. RE: Run Python 3 script with the same command on Windows, Linux, and macOS? - Gribouillis - Nov-15-2020 ssrobins Wrote:I use Python 3 scripts to automate various steps in continuous integration (CI) in Azure DevOps and GitHub Actions that runs on Windows, Linux, and macOS.Can't you just configure a variable that contains the name of the command in those tools? I mean that the fundamental theorem of software engineering also solves this issue :) |