Nicholas Pini
05/05/2026, 8:29 AMFailed to load plugin aws
Traceback (most recent call last):
File "/Users/nicholas/earthalytics-engine/flows/api/flooding_risk/.venv/lib/python3.12/site-packages/prefect/_experimental/plugins/manager.py", line 70, in load_entry_point_plugins
plugin = ep.load()
^^^^^^^^^
File "/Users/nicholas/earthalytics-engine/flows/api/flooding_risk/.venv/lib/python3.12/site-packages/importlib_metadata/__init__.py", line 221, in load
module = import_module(self.module)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nicholas/.local/share/uv/python/cpython-3.12.12-macos-aarch64-none/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 999, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/Users/nicholas/earthalytics-engine/flows/api/flooding_risk/.venv/lib/python3.12/site-packages/prefect_aws/__init__.py", line 5, in <module>
from .s3 import S3Bucket
File "/Users/nicholas/earthalytics-engine/flows/api/flooding_risk/.venv/lib/python3.12/site-packages/prefect_aws/s3.py", line 14, in <module>
from prefect import task
ImportError: cannot import name 'task' from partially initialized module 'prefect' (most likely due to a circular import) (/Users/nicholas/earthalytics-engine/flows/api/flooding_risk/.venv/lib/python3.12/site-packages/prefect/__init__.py)
This is probably due to prefect-aws, what is happening? My plugin simply adds a random env variable, so it cannot be the cause.Marvin
05/05/2026, 8:29 AMMarvin
05/05/2026, 8:32 AMprefect-aws plugin during import prefect, and in 3.6.12 that can hit a circular import bug.
What’s happening
With experimental plugins enabled, Prefect loads all registered prefect.plugins entry points as part of import-time initialization. If prefect-aws is installed, it registers an aws plugin entry point, so Prefect tries to load it automatically.
The import chain is effectively:
text
import prefect
-> Prefect initializes plugins
-> loads plugin entry point "aws"
-> imports prefect_aws
-> prefect_aws.s3 does: from prefect import task
-> but prefect is still only partially initialized
-> ImportError: cannot import name 'task' from partially initialized module 'prefect'
So the message:
text
Failed to load plugin aws
is referring to the installed prefect-aws package, not your custom plugin.
Why this happens specifically in 3.6.12
There was a bug in Prefect 3.6.12’s import order: plugin initialization happened before Prefect’s lazy import machinery was fully set up. That means from prefect import task could fail during plugin loading.
This was fixed later by moving plugin initialization to occur after __getattr__ is defined.
Relevant fix:
Fix circular import when plugins import from prefect
What to do
Best fix: upgrade Prefect
- Upgrade to at least 3.6.16 where this import-order bug was fixed
- Prefer upgrading both Prefect and prefect-aws together to compatible latest versions
Temporary workarounds
1. Disable experimental plugins if you don’t need them right now:
bash
export PREFECT_EXPERIMENTS_PLUGINS_ENABLED=0
2. Deny just the AWS plugin if you want plugins enabled but don’t need prefect-aws loaded as a plugin:
bash
export PREFECT_EXPERIMENTS_PLUGINS_DENY=aws
Bottom line
- Your plugin that adds an env var is probably not the cause.
- The failing plugin is prefect-aws, loaded automatically because plugins are enabled.
- In Prefect 3.6.12, this is a known initialization-order issue.
- Upgrading Prefect is the right fix.
If you want, I can help you pin a known-good Prefect / prefect-aws version combination for your Python 3.12 environment.Nate
05/05/2026, 3:37 PMNicholas Pini
05/06/2026, 3:29 PMNate
05/06/2026, 3:30 PM