Setting Up Python on a Windows Machine

# Install Visual C++ 14
choco install vcredist2017 -y

# Install Python 3.8
choco install python --version=3.8 -y

# Add the bin path into the local system's environmental paths
$env:path += ";C:\Python38"

# Validate installed python version
PS C:\temp> python --version
Python 3.8.0

# Install pip priviledged proxy
$env:path += ";$pyScripts"
python -m pip install mitmproxy

# Sample output
Installing collected packages: Werkzeug, MarkupSafe, Jinja2, itsdangerous, click, flask, pyparsing, hpack, hyperframe, h2, six, protobuf, kaitaistruct, blinker, typing-extensions, asgiref, pycparser, cffi, cryptography, pyOpenSSL, h11, wsproto, sortedcontainers, tornado, publicsuffix2, Brotli, pyasn1, ldap3, zstandard, passlib, certifi, urwid, pydivert, ruamel.yaml.clib, ruamel.yaml, msgpack, pyperclip, mitmproxy
Running install for kaitaistruct ... done
Running install for blinker ... done
Running install for urwid ... done
Running install for pyperclip ... done
Successfully installed Brotli-1.0.9 Jinja2-2.11.3 MarkupSafe-2.1.0 Werkzeug-1.0.1 asgiref-3.3.4 blinker-1.4 certifi-2021.10.8 cffi-1.15.0 click-7.1.2 cryptography-3.2.1 flask-1.1.4 h11-0.13.0 h2-4.1.0 hpack-4.0.0 hyperframe-6.0.1 itsdangerous-1.1.0 kaitaistruct-0.9 ldap3-2.8.1 mitmproxy-5.3.0 msgpack-1.0.3 passlib-1.7.4 protobuf-3.13.0 publicsuffix2-2.20191221 pyOpenSSL-19.1.0 pyasn1-0.4.8 pycparser-2.21 pydivert-2.1.0 pyparsing-2.4.7 pyperclip-1.8.2 ruamel.yaml-0.16.13 ruamel.yaml.clib-0.2.6 six-1.16.0 sortedcontainers-2.2.2 tornado-6.1 typing-extensions-4.1.1 urwid-2.1.2 wsproto-0.15.0 zstandard-0.14.1
WARNING: You are using pip version 20.1.1; however, version 22.0.3 is available.
You should consider upgrading via the 'C:\Python38\python.exe -m pip install --upgrade pip' command.

# Avoid these errors by adding Python scripts into environmental path
WARNING: The script flask.exe is installed in 'C:\Python38\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts mitmdump.exe, mitmproxy.exe, mitmweb.exe, pathoc.exe and pathod.exe are installed in 'C:\Python38\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

# Validate paths
PS C:\temp> $env:path
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\OpenSSL\bin;C:\Program Files (x86)\vim\vim80;;C:\Program Files\WindowsPowerShell\Scripts;C:\Users\baloo\AppData\Local\Microsoft\WindowsApps;C:\Python38

# Install vim
choco install vim -y

# Create a file with test contents
PS C:\temp> add-content C:\temp\ "print('hello world!')"

# Check file content
PS C:\temp> cat c:\temp\
print('hello world!')

# Test Python against the new file
PS C:\temp> python c:\temp\
hello world!


How to Upgrade:

# Remove older Python version
choco uninstall python
# Manually remove previous Python location from environmental variables $ENV:PATH

# Install newer Python version
choco install python -y
$newPyLocation='C:\Python310' # change to value to the correct path
$env:path += ";$pyScripts"
$env:path += ";$newPyLocation"

# Install pip (if necessary)
py -3 -m ensurepip

# Upgrade pip
python -m pip install -U pip

PS C:\Windows\system32> python.exe -m pip install --upgrade pip
Collecting pip
Downloading pip-22.0.3-py3-none-any.whl (2.1 MB)
|████████████████████████████████| 2.1 MB 6.4 MB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.1.1
Uninstalling pip-20.1.1:
Successfully uninstalled pip-20.1.1
Successfully installed pip-22.0.3

# Clear all pre-build dependencies
Get-ChildItem -Path $userTemp -Include * -File -Recurse | foreach { $_.Delete()}

# Re-install pip proxy
python -m pip install mitmproxy

Leave a Reply

Your email address will not be published. Required fields are marked *