Notes

Python on Windows

author: Paul Kim

categories: python

tags: python

Installing Python 2 and 3 on Windows

  • Install Python 2 64-bit with default options.
  • Install Python 3 64-bit with default options.

Python is installed in %LOCALAPPDATA%\Programs\Python\Python37-32

Note: add Python to path if you want to execute Python scripts from the command line

The following paths will be added to the user PATH environment variable:

  • %LOCALAPPDATA%\Programs\Python\Python37-32\
  • %LOCALAPPDATA%\Programs\Python\Python37-32\Scripts\

Python Launcher for Windows (Python 3)

# start python 3
py -3

# get python 3 version
py -3 --version

# get python 3 pip version
py -3 -m pip --version

# list installed python 3 packages
py -3 -m pip list

# install python 3 packages
py -3 -m pip install numpy matplotlib

# upgrade python 3 packages
py -3 -m pip install --upgrade pip setuptools wheel virtualenv

# uninstall python 3 packages
py -3 -m pip uninstall numpy matplotlib

# create virtual environment with venv (Python 3.3+)
py -3 -m venv path-to-venv

# create virtual environment with virtualenv (Python 3.3+)
py -3 -m virtualenv path-to-venv
virtualenv path-to-venv

# activate virtual environment
path-to-venv\Scripts\activate.bat

# freeze packages (venv)
# freeze system and local packages (virtualenv)
py -3 -m pip freeze > requirements.txt

# freeze local packages (virtualenv)
py -3 -m pip freeze -l > requirements.txt

# install required packages
py -3 -m pip install -r requirements.txt

# deactivate virtual environment
deactivate

Python Launcher for Windows (Python 2)

# start python 2
py -2

# get python 2 version
py -2 --version

# get python 2 pip version
py -2 -m pip --version

# list installed python 2 packages
py -2 -m pip list

# install python 2 packages
py -2 -m pip install numpy matplotlib

# upgrade python 2 packages
py -2 -m pip install --upgrade pip setuptools wheel virtualenv

# uninstall python 2 packages
py -2 -m pip uninstall numpy matplotlib

# create virtual environment with virtualenv (Python 2.6+)
py -2 -m virtualenv path-to-venv
virtualenv path-to-venv

# activate virtual environment
path-to-venv\Scripts\activate.bat

# freeze packages (venv)
# freeze system and local packages (virtualenv)
py -2 -m pip freeze > requirements.txt

# freeze local packages (virtualenv)
py -2 -m pip freeze -l > requirements.txt

# install required packages
py -2 -m pip install -r requirements.txt

# deactivate virtual environment
deactivate
Source

ChromeEdgeFirefoxOpera

© 2021 paulkode.com. All rights reserved.