How to run Prefect on Windows
Learn how to run Prefect server and workers on Windows with PowerShell.
Prefect provides first-class Windows support with native PowerShell integration and full feature parity with other platforms. This guide covers Windows-specific setup and best practices.
Windows support
Prefect provides comprehensive Windows support with the Windows ecosystem. Prefect automatically detects PowerShell and uses it as the default shell on Windows, allowing you to run shell commands and scripts naturally without additional configuration. The subprocess execution is fully compatible with Windows process management.
Windows path conventions are fully supported, including UNC paths for network storage. This allows you to configure Prefect to use network shares for databases, storage, and other resources, which is particularly useful in enterprise environments where shared storage is common:
Environment variables work using standard Windows conventions and can be set using PowerShell syntax, either for the current session or permanently for the user:
Shell tasks automatically use PowerShell on Windows, providing access to the full Windows command ecosystem:
Database configuration and workers
By default, Prefect uses SQLite stored at %USERPROFILE%\.prefect\prefect.db
with no additional configuration needed. For production deployments, you can configure PostgreSQL using standard connection strings:
Prefect workers on Windows support both process execution and Docker containers. Process workers run flows directly as Windows processes. Docker workers can leverage Windows containers for isolated execution environments:
Security and performance considerations
Windows environments require specific security configurations for optimal Prefect operation. You’ll need to allow Prefect server through Windows Firewall and configure PowerShell execution policies. Additionally, antivirus software can significantly impact performance if not configured properly.
Configure Windows Firewall to allow Prefect server traffic on port 4200:
If you encounter PowerShell execution policy errors when running scripts or deployments, configure the execution policy for the current user:
For better performance, consider adding these directories to your antivirus exclusions: %USERPROFILE%\.prefect\
, your Python installation directory, and temporary directories used by flows. This prevents real-time scanning from interfering with Prefect operations.
Production deployment as Windows service
For production environments, you should run Prefect server as a Windows service to ensure it starts automatically and runs reliably. The Non-Sucking Service Manager (NSSM) is the recommended tool for this purpose. Download NSSM from nssm.cc and install the service with administrator privileges:
This configuration ensures Prefect server starts automatically when Windows boots and provides proper service management capabilities including automatic restarts on failure.
Troubleshooting common Windows issues
Several Windows-specific issues can occur when running Prefect. The most common problems relate to PATH configuration, encoding issues, port conflicts, and permission errors.
Command not found errors
These typically indicate PATH issues. Verify that the Python Scripts directory is in your PATH and restart PowerShell after making changes. You can also try running where prefect
to see if the command is found.
For example, if the prefect
command isn’t found, you’ll need to add the Python Scripts directory to your PATH
. This is a common issue on Windows when Python isn’t installed system-wide:
Port conflicts
These can prevent the server from starting. Check what’s using port 4200 and kill the process if necessary:
Alternatively, you can configure Prefect server to use a different port by setting the PREFECT_SERVER_API_HOST
and PREFECT_SERVER_API_PORT
environment variables:
Character encoding errors
Character encoding errors (particularly 'charmap' codec
errors) can occur on some Windows systems. Set the Python I/O encoding to UTF-8:
Permission errors
Permission errors often require running PowerShell as Administrator for system-wide changes, or checking file permissions on Prefect directories. Network connectivity issues typically involve Windows Firewall rules or corporate proxy settings.
Additional Resources
For additional help with Windows-specific issues, check the Prefect Community Slack, search GitHub Issues for Windows-related problems, or review PowerShell execution logs for detailed error messages.