Quick Guide For Fixing/Installing Python, PyTorch, CUDA, Triton, Sage Attention and Flash Attention For Local AI Image Generation
With all the new local image & video generation tools coming out I've been seeing a lot of posts and error threads being opened for various issues with cuda/pytorch/sage attantion/triton/flash attention. I was tired of digging links up so I initially made this as a cheat sheet for myself but expanded it with hopes that this will help some of you get your venvs and systems running smoothly.
- Check Installed Python Versions
- Set Default Python Version by Changing PATH
- Installing VS Build Tools
- Check the Currently Active CUDA Version
- Download and Install the Correct CUDA Toolkit
- Change System CUDA Version in PATH
- Install to a VENV
- Check All Your Dependency Versions Easy
- Install PyTorch
- Install Triton
- Install SageAttention
- Install FlashAttention
- Installing A Fresh Venv
- For ComfyUI Portable Users
- Other Missing Dependencies
- Notes
To list all installed versions of Python on your system, open cmd and run:
py -0p
The version number with the asterix next to it is your system default.
You can have multiple versions installed on your system. The version of Python that runs when you type python
is determined by the order of Python directories in your PATH variable. The first python.exe
found is used as the default.
Steps:
- Open the Start menu, search for
Environment Variables
, and select Edit system environment variables. - In the System Properties window, click Environment Variables.
- Under System variables (or User variables), find and select the
Path
variable, then click Edit. - Move the entry for your desired Python version (for example,
C:\Users\<yourname>\AppData\Local\Programs\Python\Python310\
and itsScripts
subfolder) to the top of the list, above any other Python versions. - Click OK to save and close all dialogs.
- Restart your command prompt and run:python --version
It should now display your chosen Python version.
The easiest way to install VS Build Tools is using Windows Package Manager (winget). Open a command prompt and run:
winget install --id=Microsoft.VisualStudio.2022.BuildTools -e
For VS Build Tools 2019 (if needed for compatibility):
winget install --id=Microsoft.VisualStudio.2019.BuildTools -e
For VS Build Tools 2015 (rarely needed):
winget install --id=Microsoft.BuildTools2015 -e
After installation, you can verify that VS Build Tools are correctly installed by running: cl.exe
or msbuild -version
If installed correctly, you should see version information rather than "command not found"
Remeber to restart your computer after installing
For a more detailed guide on VS Build tools see here.
To see which CUDA version is currently active, run:
nvcc --version
Note: This is only for the system for self contained environments it's always included.
Download and install from the official NVIDIA CUDA Toolkit page:
https://developer.nvidia.com/cuda-toolkit-archive
Install the version that you need. Multiple version can be installed.
- Search for
env
in the Windows search bar. - Open Edit system environment variables.
- In the System Properties window, click Environment Variables.
- Under System Variables, locate
CUDA_PATH
. - If it doesn't point to your intended CUDA version, change it. Example value:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4
From this point to install any of these to a virtual environment you first need to activate it. For system you just skip this part and run as is.
Open a command prompt in your venv/python folder (folder name might be different) and run:
Scripts\activate
You will now see (venv)
in your cmd. You can now just run the pip commands as normal.
Make or download this versioncheck.py file. Edit it with any text/code editor and paste the code below. Open a CMD to the root folder and run with:
python
versioncheck.py
This will print the versions for torch, CUDA, torchvision, torchaudio, CUDA, Triton, SageAttention, FlashAttention. To use this in a VENV activate the venv first then run the script.
import sys
import torch
import torchvision
import torchaudio
print("python version:", sys.version)
print("python version info:", sys.version_info)
print("torch version:", torch.__version__)
print("cuda version (torch):", torch.version.cuda)
print("torchvision version:", torchvision.__version__)
print("torchaudio version:", torchaudio.__version__)
print("cuda available:", torch.cuda.is_available())
try:
import flash_attn
print("flash-attention version:", flash_attn.__version__)
except ImportError:
print("flash-attention is not installed or cannot be imported")
try:
import triton
print("triton version:", triton.__version__)
except ImportError:
print("triton is not installed or cannot be imported")
try:
import sageattention
print("sageattention version:", sageattention.__version__)
except ImportError:
print("sageattention is not installed or cannot be imported")
except AttributeError:
print("sageattention is installed but has no __version__ attribute")
This will print the versions for torch, CUDA, torchvision, torchaudio, CUDA, Triton, SageAttention, FlashAttention.
torch version: 2.6.0+cu126
cuda version (torch): 12.6
torchvision version: 0.21.0+cu126
torchaudio version: 2.6.0+cu126
cuda available: True
flash-attention version: 2.7.4
triton version: 3.2.0
sageattention is installed but has no version attribute
Use the official install selector to get the correct command for your system:
Install PyTorch
To install Triton for Windows, run:
pip install triton-windows
For a specific version:
pip install triton-windows==3.2.0.post10
Triton Windows releases and info:
If you encounter any errors such as: AttributeError: module 'triton' has no attribute 'jit'
then head to C:\Users\your-username.triton\
and delete the cache folder.
Get the correct prebuilt Sage Attention wheel for your system here:
pip install sageattention "path to downloaded wheel"
Example :
pip install sageattention "D:\sageattention-2.1.1+cu124torch2.5.1-cp310-cp310-win_amd64.whl"
`sageattention-2.1.1+cu124torch2.5.1-cp310-cp310-win_amd64.whl`
This translates to being compatible with Cuda 12.4 | Py Torch 2.5.1 | Python 3.10 and 2.1.1 is the SageAttention version.
If you get an error : SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
then make sure to downgrade your triton to v3.2.0-windows.post10. Download wheel and install manually with:
CMD into python folder then run :
python.exe -s -m pip install --force-reinstall "path-to-triton-3.2.0-cp310-cp310-win_amd64.whl"
Get the correct prebuilt Flash Attention wheel compatible with your python version here:
pip install "path to downloaded wheel"
You can install a new python venv in your root folder by using the following command. You can change C:\path\to\python310 to match your required version of python. If you just use python -m venv venv
it will use the system default version.
"C:\path\to\python310\python.exe" -m venv venv
To activate and start installing dependencies
your_env_name\Scripts\activate
Most projects will come with a requirements.txt to install this to your venv
pip install -r requirements.txt
The process here is very much the same with one small change. You just need to use the python.exe in the python_embedded folder to run the pip commands. To do this just open a cmd at the python_embedded folder and then run:
python.exe -s -m pip install your-dependency
If you see any other errors for missing modules for any other nodes/extensions you may want to use it is just a simple case of getting into your venv/standalone folder and installing that module with pip.
Example: No module 'xformers'
pip install xformers
Occasionaly you may come across a stubborn module and you may need to force remove and reinstall without using any cached versions.
Example:
pip uninstall -y xformers
pip install --no-cache-dir --force-reinstall xformers
- Make sure all versions (Python, CUDA, PyTorch, Triton, SageAttention) are compatible this is the primary reason for most issues.
- Each implementation will have its own requirements which is why we use a standalone environment.
- Restart your command prompt after making changes to environment variables or PATH.
- If I've missed anything please leave a comment and I will add it to the post.
- To easily open a cmd prompt at a specific folder browse to the folder you need in file manager then type cmd in the address bar and hit enter.
Update 21st April 2025
- Added Triton & Sage Attention common error fixes
Update 20th April 2025
- Added VS build tools section
- Fixed system cuda being optional
Update 19th April 2025
- Added comfyui portable instructions.
- Added easy CMD opening to notes.
- Fixed formatting issues.