Q:

How to delete Windows User Environment Variable from registry

With this simple setup I can create any User Environment variable in the registry:
import win32con
import win32gui
import _winreg as winreg

def set_environment_variable(variable, value, user_env=True):
    if user_env: reg_key = winreg. OpenKey(winreg. HKEY_CURRENT_USER, 'Environment', 0, winreg. KEY_SET_VALUE)
    else: reg_key = winreg. OpenKey(winreg. HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 0, winreg. KEY_SET_VALUE)

    if '%' in value: var_type = winreg. REG_EXPAND_SZ
    else: var_type = winreg. REG_SZ

    with reg_key:
        winreg. SetValueEx(reg_key, variable, 0, var_type, value)     
    win32gui. SendMessageTimeout(win32con. HWND_BROADCAST, win32con. WM_SETTINGCHANGE, 0, 'Environment', win32con. SMTO_ABORTIFHUNG, 1000)

create a MY_VARIABLE:
set_environment_variable('MY_VARIABLE', 'MY_VALUE')

Here is the screenshot:

Question: How do I delete just created MY_VARIABLE? 

A:

You can easily set or remove an environment variable from the Windows registry with:
def set_environment_variable(variable, value, user_env=True):
    """
    Set/Remove Environment variable from windows registry. 

    :param variable: Environment Variable Name
    :param value: Environment Variable Value (None to delete)
    :param user_env: if true set in user env instead of in system env
    :return: None
    """
    if user_env:
        # This is for the user's environment variables
        reg_key = winreg. OpenKey(
            winreg. HKEY_CURRENT_USER,
            'Environment', 0, winreg. KEY_SET_VALUE)
    else:
        # This is for the system environment variables
        reg_key = winreg. OpenKey(
            winreg. HKEY_LOCAL_MACHINE,
            r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
            0, winreg. KEY_SET_VALUE)

    with reg_key:
        if value is None:
            winreg. DeleteValue(reg_key, variable)
        else:
            if '%' in value:
                var_type = winreg. REG_EXPAND_SZ
            else:
                var_type = winreg. REG_SZ
            winreg. SetValueEx(reg_key, variable, 0, var_type, value)

    # notify about environment change
    win32gui. SendMessageTimeout(
        win32con. HWND_BROADCAST, win32con. WM_SETTINGCHANGE, 0,
        'Environment', win32con. SMTO_ABORTIFHUNG, 1000)

To set the environment variable:
set_environment_variable('MY_VARIABLE', 'MY_VALUE)

To remove the environment variable:
set_environment_variable('MY_VARIABLE', None)

You can import the win32 libs with:
import win32con
import win32gui
try:
    import _winreg as winreg
except ImportError:
    # this has been renamed in python 3
    import winreg

