Author vstinner
Recipients eric.araujo, nils, tarek, vstinner, zegreek
Date 2010-11-09.00:59:19
SpamBayes Score 4.38538e-15
Marked as misclassified No
Message-id <>
Now I get an error in copy_scripts() function of Lib/distutils/command/ this function adjusts Python shebang of installed Python scripts. The problem is that the shebang contains a non-ASCII character whereas the script is written into the locale encoding, which is ASCII in my test.

test_httpservers has a similar issue: CGIHTTPServerTestCase fails if the Python executable full path is not encodable to utf-8. I fixed simply this issue by skipping the test:

        # The python executable path is written as the first line of the
        # CGI Python script. The encoding cookie cannot be used, and so the
        # path should be encodable to the default script encoding (utf-8)
    except UnicodeEncodeError:
        raise self.skipTest(
            "Python executable path is not encodable to utf-8")


Attached patch, copy_script.patch, fixes this issue by reading the Python script in binary mode. It ensures that the shebang is decodable from utf-8 and the script encoding.

It checks with utf-8 because the shebang is always written before the encoding cookie, and so the parser reads the shebang with the default parser encoding, which is utf-8. Eg. with a shebang not decodable from utf-8:
  File "./", line 1
SyntaxError: Non-UTF-8 code starting with '\xff' in file ./ on line 1, but no encoding declared; see for details

It checks with the script encoding because when the parser hits the encoding cookie, it restarts to read the whole file with the encoding, and so the parser decodes the shebang from the script encoding.
Date User Action Args
2010-11-09 00:59:27vstinnersetrecipients: + vstinner, tarek, eric.araujo, zegreek, nils
2010-11-09 00:59:26vstinnersetmessageid: <>
2010-11-09 00:59:23vstinnerlinkissue6011 messages
2010-11-09 00:59:22vstinnercreate