To make a Python script executable on Linux and bash, one uses the shebang
#! /usr/bin/env python
as the first line of the script. If this line happens to end with the Windows-style newline \r\n (carriage return - line feed), instead of the Unix-style newline \n, then bash will not be able to run the script through the Python interpreter.
I am doing cross-platform development in Python. When I work in Windows, the natural newline is \r\n. When I work in Linux, the natural newline is \n. Given that I use Mercurial for version control, what would be the best way to enforce the use of the \n newline in the script file containing the shebang?
The common approach is not to generate the outer wrapper scripts yourself at all, but specify them in your setup.py and let them be generated during package installation.
If you do something like the following:
setup(
entry_points = {
"console_scripts": [
"script_name": "your.module.name:main",
],
}
)
...then, on installation, a wrapper named script_name will be generated and installed, and configured appropriately to run on your current platform (shebang line and all). This makes the end-of-line characters in use moot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With