Search code examples
pythonshellscriptingpyc

Stop Python from generating pyc files in shebang


Is there a way to stop python from creating .pyc files, already in the shebang (or magic number if you will) of the Python script?

Not working:

#!/usr/bin/env python -B

Solution

  • Yes, if and only if, we assume the Python program runs in a somewhat POSIX compatible system (for /bin/sh), this will work:

    (IMPROVED based on input from glglgl)

    #!/bin/sh
    "exec" "python" "-B" "$0" "$@"
    
    # The rest of the Python program follows below: