Chapter 3. Using Python on Windows 28 Python Setup and Usage, Release 3.9.5 From file associations 3.8.2 Shebang Lines For example, if the first line of your script starts with 3.8.3 Arguments in shebang lines The launcher should have been associated with Python files (i.e. .py ,$_{.pyw}$ ,$_{.pyc}$ files) when it was installed. This means that when you double-click on one of these files from Windows explorer the launcher will be used, and therefore you can use the same facilities described above to have the script specify the version which should be used. The key benefit of this is that a single launcher can support multiple Python versions at the same time depending on the contents of the first line. If the first line of a script file starts with$_{#!}$ , it is known as a “shebang” line. Linux and other Unix like operating systems have native support for such lines and they are commonly used on such systems to indicate how a script should be executed. This launcher allows the same facilities to be used with Python scripts on Windows and the examples above demonstrate their use. To allow shebang lines in Python scripts to be portable between Unix and Windows, this launcher supports a number of ‘virtual’ commands to specify which interpreter to use. The supported virtual commands are: #! /usr/bin/python The default Python will be located and used. As many Python scripts written to work on Unix will already have this line, you should find these scripts can be used by the launcher without modification. If you are writing a new script on Windows which you hope will be useful on Unix, you should use one of the shebang lines starting with$_{/usr}$ . Any of the above virtual commands can be suffixed with an explicit version (either just the major version, or the major and minor version). Furthermore the 32-bit version can be requested by adding “-32” after the minor version. I.e.$_{/usr/bin/python2.7-32}$ will request usage of the 32-bit python 2.7. New in version 3.7: Beginning with python launcher 3.7 it is possible to request 64-bit version by the “-64” suffix. Furthermore it is possible to specify a major and architecture without minor (i.e.$_{/usr/bin/python3-64}$ ). The$_{/usr/bin/env}$ form of shebang line has one further special property. Before looking for installed Python interpreters, this form will search the executable$_{PATH}$ for a Python executable. This corresponds to the behaviour of the Unix$_{env}$program, which performs a$_{PATH}$ search. The shebang lines can also specify additional options to be passed to the Python interpreter. For example, if you have a shebang line: #! /usr/bin/python -v Then Python will be started with the$_{-v}$ option • python • /usr/local/bin/python • /usr/bin/python • /usr/bin/env python