Building a Local AI Image Generation Environment Without a CS Background
Running AI tools locally keeps your prompts, materials, and generated images on your own computer without uploading them to third-party platforms. However, dependency conflicts, driver issues, and terminal errors often deter non-technical creators. This article provides a step-by-step guide to setting up a local AI image generation environment using ComfyUI on Windows (NVIDIA) and Apple Silicon Mac. It covers hardware checks, environment setup, PyTorch installation, VRAM monitoring, troubleshooting, and backup strategies.
Running AI tools locally ensures that your materials, prompts, and generation results stay on your computer without being uploaded to third-party platforms. However, dependency conflicts, driver version mismatches, and terminal errors often stop creators without a technical background. This article breaks down each step in order, providing commands, verification methods, and common troubleshooting tips. The primary scenarios covered are Windows (NVIDIA GPUs) and Apple Silicon Macs. By following these steps, you should be able to run ComfyUI locally, monitor VRAM usage, and back up your environment.
1. Preparation Before Starting
The complete process consists of six steps: confirming hardware, installing uv and a virtual environment, installing PyTorch, installing and running ComfyUI, monitoring VRAM, and backing up the environment. Excluding model download time, the entire process usually takes 1 to 3 hours depending on network speed. Before starting, please prepare:
- A computer with internet access and administrator privileges to install GPU drivers.
- At least 50 GB of free disk space.
- A text file to record commands and error messages for easy troubleshooting.
After completing each step, run the provided verification command. Only proceed to the next step if the verification passes to reduce troubleshooting efforts later.
2. Confirming Hardware, System, and Disk Space
Before installation, confirm three things: GPU type, chip or OS version, and disk space.
| Environment | Check Method | Criteria |
|---|---|---|
| Windows with NVIDIA GPU | Open PowerShell, run nvidia-smi |
Should display GPU model and CUDA Version |
| Apple Silicon Mac | Apple menu > About This Mac | Chip should be M-series for MPS acceleration |
| Intel Mac or Windows without NVIDIA GPU | Same as above | No CUDA or MPS acceleration; CPU only, image generation will be slow |
| Disk Space | File Explorer or Finder | Recommend reserving at least 50 GB |
If nvidia-smi cannot run on Windows, it is usually because the GPU driver is not installed or installed improperly. Download the latest stable driver from the GPU manufacturer’s official website, install it, restart your computer, and run it again. If it still says “not recognized as an internal or external command,” check if nvidia-smi.exe exists in the C:\Windows\System32 folder in File Explorer.
The CUDA Version in the top right corner of nvidia-smi indicates the maximum CUDA version supported by the current driver. When installing PyTorch in step 4, select a version no higher than this number.
Estimate disk space based on usage. The base environment (Python dependencies and PyTorch) takes up a few GB, and ComfyUI itself is small, but model files vary greatly. An SD 1.5 model is about 2 GB, an SDXL model is commonly 6 to 7 GB, and newer large models may exceed 10 GB. Generated images will also continue to accumulate. If you only put one or two SDXL models, 50 GB is usually sufficient. If you have many models, you can use ComfyUI’s extra_model_paths.yaml file to point the model directory to another hard drive. When the disk is nearly full, the system and program may behave abnormally, so clean the output directory regularly.
Intel Macs or computers without NVIDIA GPUs can also complete these steps. ComfyUI can run with the --cpu parameter, but a single image may take several minutes, and memory usage will be high. It is recommended to have at least 16 GB of memory and test with small sizes and lightweight models first. These computers are suitable for learning and testing, but not for batch image generation.
3. Installing uv and Creating a Virtual Environment
uv is a tool for managing Python versions and dependencies. A virtual environment isolates this project’s dependencies from other system software to avoid conflicts.
- Visit the uv official documentation (docs.astral.sh/uv) and install it according to your system’s instructions.
- Close and reopen the terminal, then run
uv --version. If a version number is displayed, the installation is successful. - Create a new project folder, such as
D:\AI-Artor~/AI-Art, navigate to it, and runuv venv --python 3.12to create the virtual environment. - Activate the virtual environment. On Windows PowerShell, run
.venv\Scripts\activate. On Mac terminal, runsource .venv/bin/activate. Once activated,(.venv)will appear at the beginning of the command line.
Verification: Run python --version. If it shows 3.12.x, it is correct.
4. Installing PyTorch and Confirming Acceleration
PyTorch is the foundational framework for running ComfyUI. Windows users need to install the CUDA version; otherwise, ComfyUI will only use the CPU.
Windows NVIDIA users should visit the Get Started page on pytorch.org, select Windows as the OS, pip as the package manager, and a compute platform version no higher than the CUDA Version shown by nvidia-smi. The page will generate an installation command where the number after cu is the CUDA version. For example, if the driver shows 12.8, you can choose cu128 or cu126. The command format is similar to:
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
Version numbers change over time, so use the command generated by the official website.
Mac users should select macOS and pip on the pytorch.org page and run the generated command. The Apple Silicon version of PyTorch includes MPS support by default.
Verification: On Windows NVIDIA, run python -c "import torch; print(torch.__version__, torch.cuda.is_available())". The result should end with True. On Mac, run python -c "import torch; print(torch.backends.mps.is_available())". The result should be True.
If the result on Windows is False, it is mostly due to an outdated driver or installing the CPU version. Update the driver first, then re-run the installation command from this step.
5. Installing and Running ComfyUI
- Download ComfyUI. Users with git installed can run
git clone https://github.com/comfyanonymous/ComfyUI.git. Users unfamiliar with command lines can download the zip archive from the official GitHub page and extract it to the project folder. - Navigate to the ComfyUI folder, ensure the virtual environment is still active, and run
uv pip install -r requirements.txt. - Run the PyTorch verification command from Step 4 again. If
torch.cuda.is_available()becomes False, it means the PyTorch may have been replaced during dependency installation. Simply re-run the installation command from Step 4. - Run
python main.py. Once the terminal displays the service address, openhttp://127.0.0.1:8188in a browser.
Place your model files (usually in .safetensors format) into the ComfyUI/models/checkpoints folder. Return to the web page and refresh it. Select the model in the Load Checkpoint node and click Queue Prompt to start generating. The first image generation is usually slow because the program needs to load the model into VRAM.
6. Monitoring VRAM to Determine Operating Status
When generating images on a Windows NVIDIA system, open another PowerShell window and run nvidia-smi -l 1. The command refreshes every second, and the Memory-Usage column shows used and total VRAM. Press Ctrl+C to stop refreshing.
Windows users can also open Task Manager, switch to the “Performance” tab, select GPU, and check “Dedicated GPU memory”.
Mac users should open the “Memory” tab in Activity Monitor. On Apple Silicon, the CPU and GPU share unified memory, so memory pressure will reflect GPU operation simultaneously. If the memory pressure remains red for a long time, consider switching to a smaller model or lowering the resolution.
VRAM usage increases during image generation and should drop back to a lower level after completion. If it remains fully occupied long after generation stops, you can close and restart ComfyUI to clear the cache.
7. Common Troubleshooting
| Symptom | Possible Cause | Solution |
|---|---|---|
nvidia-smi says not recognized as an internal or external command |
Driver not installed or installed improperly | Reinstall the latest stable driver and restart; check if nvidia-smi.exe is in System32 |
| Running activate says running scripts is disabled | PowerShell execution policy restriction | Run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned, applies only to the current user |
torch.cuda.is_available() is False |
Installed CPU version, or driver version is lower than the selected CUDA version | Update driver, re-run the installation command from Step 4 |
CUDA out of memory error during generation |
Insufficient VRAM | Lower resolution, reduce batch size, use a smaller model, or add --lowvram at startup (use python main.py --help to view parameters) |
| Cannot find model in the web page | Model placed in the wrong folder or page not refreshed | Confirm the file is in models/checkpoints and refresh the page |
| Port 8188 is already in use | A previous ComfyUI is still running | Close the old window, or run python main.py --port 8189 to change the port |
| Mac reports MPS-related errors for some operations | MPS support is incomplete for a few operations | Update PyTorch and ComfyUI; try setting the environment variable PYTORCH_ENABLE_MPS_FALLBACK=1 |
| Error indicating Python version mismatch | Not running in a virtual environment | Ensure (.venv) is at the beginning of the command line; reactivate if necessary |
When encountering other errors, first copy the complete error message and search based on keywords. Save the error message along with system information for easier troubleshooting later.
8. Backup and Recovery
The goal of environment backup is to be able to run it again in a new folder if the computer has issues or files are accidentally deleted. Different content requires different backup methods.
- Dependency list: Run
uv pip freeze > requirements-lock.txtin the virtual environment to record all dependency versions. - ComfyUI settings: Back up the
ComfyUI/userfolder, which contains workflows and settings. - Custom nodes: Record the name and source URL of each plugin in the
custom_nodesfolder so they can be reinstalled during recovery. - Model files: Large in size, usually not backed up entirely. You should record the download source and SHA256 checksum of each model. On Windows, you can run
Get-FileHash <filename> -Algorithm SHA256in PowerShell to get the checksum. - Output images: Copy them separately to another hard drive or cloud storage.
After recovery, check in the following order: create a new virtual environment, install the contents of the dependency list, run the verification command from Step 4, then start ComfyUI and generate an image using a small model. If the PyTorch version has a +cu suffix, you need to specify the corresponding --index-url during recovery, otherwise it may install the CPU version.
9. Copyright, Privacy, and Model Licensing
Running locally only means data is not uploaded to third-party platforms; it does not exempt the user from legal responsibilities.
- Model licensing: Each model page has licensing terms. Some models are for personal or non-commercial use only, which should be confirmed before use.
- Reference images and materials: When using others’ images, photos, or art styles as input, ensure you have legal authorization.
- Portraits and privacy: Do not generate or modify others’ portraits without their consent, and do not use them for impersonation, fraud, or harassment.
- Download sources: Only download models and plugins from official pages or trusted sources. Files from unknown sources may contain malicious code.
It is recommended to create a “Sources and Licenses” record sheet in your working folder, detailing the source, license type, and usage scope of each model and material. This record is very useful when you need to prove authorization.
