[issue25405] User install of 3.5 removes py.exe from C:\Windows

eryksun report at bugs.python.org
Sat Oct 17 00:00:34 EDT 2015


eryksun added the comment:

Setting a new default for py.exe doesn't require admin privileges. You can use the PY_PYTHON environment variable:

    C:\>py --version
    Python 2.7.10

    C:\>set PY_PYTHON=3

    C:\>py --version
    Python 3.5.0

which you can easily persist in the registry using setx.exe:

    C:\>setx PY_PYTHON 3

    SUCCESS: Specified value was saved.

Check that it was saved:

    C:\>reg query HKCU\Environment /v PY_PYTHON

    HKEY_CURRENT_USER\Environment
        PY_PYTHON    REG_SZ    3

You can also use %LOCALAPPDATA%\py.ini to set the default:

    C:\>py --version
    Python 2.7.10

    C:\>copy con "%localappdata%\py.ini"
    [defaults]
    python=3
    ^Z
            1 file(s) copied.

    C:\>py --version
    Python 3.5.0

Note that the environment variable is preferred:

    C:\Temp>set PY_PYTHON=2
    
    C:\Temp>py --version
    Python 2.7.10

and an active virtual environment is most preferred:

    C:\Temp>py -3.5 -m venv testenv

    C:\Temp>testenv\Scripts\activate.bat

    (testenv) C:\Temp>py --version
    Python 3.5.0
    (testenv) C:\Temp>py -c "import sys; print(sys.prefix)"
    C:\Temp\testenv

----------
nosy: +eryksun

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25405>
_______________________________________


More information about the Python-bugs-list mailing list