Python Install

1. Install Python on Debian Linux

1.1. Install

  1. Update package list

    sudo apt update
  2. Install software-properties-common to manage PPAs (Personal Package Archives):

    sudo apt install software-properties-common
  3. Add the deadsnakes PPA which is used for installing multiple Python versions

    sudo add-apt-repository ppa:deadsnakes/ppa
  4. Install Python

    sudo apt install -y python3.11
  5. Optionally install TK for GUI creation

    sudo apt install -y python3-tk
    1. Now you’ll see new folders here

      /usr/lib
      example
      ls -ltr /usr/lib
      
      drwxr-xr-x   3 root root    4096 May 20 20:06 tcltk
      drwxr-xr-x 117 root root   86016 May 20 20:06 x86_64-linux-gnu
      drwxr-xr-x   2 root root    4096 May 20 20:06 blt2.5
      drwxr-xr-x  32 root root    4096 May 20 20:06 python3.10
      drwxr-xr-x   6 root root    4096 May 20 20:06 python3.11

1.2. Confirm Install

  1. Get the version number

    python3 -V
    Sample output
    python3 -V
    Python 3.10.12
  2. Test TK - this should pop up an X window.

    python3 -c "import tkinter as tk; root = tk.Tk(); root.mainloop()" &

2. Install Python on Windows

  • Full document can be found here.

2.1. Download Python for Windows

  • Download from here

  • Install with default options.

2.1.1. Confirm the Install

  • Open a cmd window and run the following command:

    $ py --list-paths
    Installed Pythons found by C:\WINDOWS\py.exe Launcher for Windows *
    
    
     -3.10-64       C:\Users\<user_name>\AppData\Local\Programs\Python\Python310\python.exe

3. Configure VS Code

3.1. Install Extensions

3.1.1. Generic

  • Install these extensions:

    1. AsciiDoc

    2. Docker

    3. Draw.io Integration

    4. Excel Viewer

    5. Fluent Icons (product icons for vertical nav bar)

    6. HTML Preview

    7. Material Icon Theme (icons for files)

    8. Real Visual Studio

    9. Remote Development

    10. REST Client

    11. YAML

3.1.2. Python

  • Launch VS Code.

  • Install the Python extension for VS Code from the Visual Studio Marketplace.

  • Configure the Python Interpreter:

    1. Open the Command Palette via Ctrl+Shift+P and start typing the Python: Select Interpreter command to search, then select the command.

    2. For a fresh install, enter the following path:

      C:\Users\<username>\AppData\Local\Programs\Python\Python3xx
  • Configure the Pylance Language Server

    • Open the Settings Menu in order to configure the following:

      • Enable Type Checking

        VSC-Pylance-EnableTypeChecking

3.1.3. Test Python

  • Create Test script

  • Create a Hello-World.py script.

    def main():
        msg = "Hello World"
        print(msg)
        party_invite()
    
    def party_invite():
        # get the age from the current user
        age_input = input('Please enter your age: ')
        age = int(age_input)
    
        # decide if they are eligible for the after party
        if age >= 21:
            print("Hey, we're having an after party.")
            print('Drop by 123 Vine St at 8pm')
        else:
            print('Nice to meet you but you are to young to party :-(')
        return
    
    
    main()

3.1.4. Run Test Script

  • Run by clicking the play button in the top-right side of the editor.

3.1.5. Debug Test Script

  • Create breakpoints in the gutter of the editor.

  • Via the same play button, click the drop down arrow and select Debug Python File.

4. Learning Resources

4.1. Training