Python Frequently Asked Questions, Release 3.9.5 2.1.3 How can I create a stand-alone binary from a Python script? You don’t need the ability to compile Python to C code if all you want is a stand-alone program that users can download and run without having to install the Python distribution first. There are a number of tools that determine the set of modules required by a program and bind these modules together with a Python binary to produce a single executable. One is to use the freeze tool, which is included in the Python source tree as Tools/freeze . It converts Python byte code to C arrays; a C compiler you can embed all your modules into a new program, which is then linked with the standard Python modules. It works by scanning your source recursively for import statements (in both forms) and looking for the modules in the standard Python path as well as in the source directory (for built-in modules). It then turns the bytecode for modules written in Python into C code (array initializers that can be turned into code objects using the marshal module) and creates a custom-made config file that only contains those built-in modules which are actually used in the program. It then compiles the generated C code and links it with the rest of the Python interpreter to form a self-contained binary which acts exactly like your script. The following packages can help with the creation of console and GUI executables: • Nuitka (Cross-platform) • PyInstaller (Cross-platform) • PyOxidizer (Cross-platform) • cx_Freeze (Cross-platform) • py2app (macOS only) • py2exe (Windows only) 2.1.4 Are there coding standards or a style guide for Python programs? 2.2 Core Language 2.2.1 Why am I getting an UnboundLocalError when the variable has a value? Yes. The coding style required for standard library modules is documented as PEP 8 . It can be a surprise to get the UnboundLocalError in previously working code when it is modified by adding an assignment statement somewhere in the body of a function. This code: >>> x =10 >>>def bar(): ... print(x) >>> bar() 10 >>> x =10 >>>def foo(): ... print(x) ... x +=1 works, but this code: results in an UnboundLocalError: Chapter 2. Programming FAQ 8