Python cheatsheet

Posted by John Liu on Sunday, February 4, 2024

To find the Python installed pathes, under DOS command:

where python

In the Python interpreter, type following Python commands:

import os
import sys
os.path.dirname(sys.executeable)

or under DOS command:

py -c "import os, sys; print(os.path.dirname(sys.executable))"

To find the Python version, under DOS command:

py --version
py -V
py -VV

To create a dedicated environment.

# from PowerShell / cmd
python -m venv .env

To use/activate the dedicated environment created above

.\.env\Scripts\activate   # PowerShell: .\.env\Scripts\Activate.ps1

To uninstall modules

pip uninstall -y <module name>

To display module version, location etc. info

pip show torch optimum onnx onnxruntime