Closed ikrommyd closed 2 months ago
well, that's a weird one. That error is inside dask itself.
Can you try:
from dask import blockwise
Does that fail?
Can you try:
from dask import blockwise
Does that fail?
@lgray yeah that errors out with ImportError: cannot import name 'clone_key' from partially initialized module 'dask.base' (most likely due to a circular import)
$ docker run --rm -ti python:3.12 /bin/bash
root@330e3f07c6ad:/# python -m venv venv && . venv/bin/activate
(venv) root@330e3f07c6ad:/# python -m pip --quiet install --upgrade uv
(venv) root@330e3f07c6ad:/# uv pip install dask dask-histogram
Resolved 12 packages in 466ms
Prepared 12 packages in 469ms
Installed 12 packages in 28ms
+ boost-histogram==1.5.0
+ click==8.1.7
+ cloudpickle==3.0.0
+ dask==2024.9.0
+ dask-histogram==2024.3.0
+ fsspec==2024.9.0
+ locket==1.0.0
+ numpy==2.1.1
+ packaging==24.1
+ partd==1.4.2
+ pyyaml==6.0.2
+ toolz==0.12.1
(venv) root@330e3f07c6ad:/# python -c 'from dask import blockwise'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/venv/lib/python3.12/site-packages/dask/__init__.py", line 5, in <module>
from dask.base import (
File "/venv/lib/python3.12/site-packages/dask/base.py", line 1039, in <module>
from dask import multiprocessing as dask_multiprocessing
File "/venv/lib/python3.12/site-packages/dask/multiprocessing.py", line 19, in <module>
from dask.optimization import cull, fuse
File "/venv/lib/python3.12/site-packages/dask/optimization.py", line 10, in <module>
from dask._task_spec import GraphNode
File "/venv/lib/python3.12/site-packages/dask/_task_spec.py", line 90, in <module>
from dask.sizeof import sizeof
File "/venv/lib/python3.12/site-packages/dask/sizeof.py", line 318, in <module>
_register_entry_point_plugins()
File "/venv/lib/python3.12/site-packages/dask/sizeof.py", line 309, in _register_entry_point_plugins
registrar = entry_point.load()
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
module = import_module(match.group('module'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/dask_histogram/__init__.py", line 6, in <module>
from dask_histogram.core import (
File "/venv/lib/python3.12/site-packages/dask_histogram/core.py", line 13, in <module>
from dask.blockwise import BlockwiseDep, blockwise, fuse_roots, optimize_blockwise
File "/venv/lib/python3.12/site-packages/dask/blockwise.py", line 13, in <module>
from dask.base import clone_key, get_name_from_key, tokenize
ImportError: cannot import name 'clone_key' from partially initialized module 'dask.base' (most likely due to a circular import) (/venv/lib/python3.12/site-packages/dask/base.py)
(venv) root@330e3f07c6ad:/#
It seems that there's an interference effect though given install of just dask
works:
$ docker run --rm -ti python:3.12 /bin/bash
root@1218450f6a25:/# python -m venv venv && . venv/bin/activate
(venv) root@1218450f6a25:/# python -m pip --quiet install --upgrade uv
(venv) root@1218450f6a25:/# uv pip install dask
Resolved 9 packages in 421ms
Prepared 9 packages in 209ms
Installed 9 packages in 7ms
+ click==8.1.7
+ cloudpickle==3.0.0
+ dask==2024.9.0
+ fsspec==2024.9.0
+ locket==1.0.0
+ packaging==24.1
+ partd==1.4.2
+ pyyaml==6.0.2
+ toolz==0.12.1
(venv) root@1218450f6a25:/# python -c 'from dask.base import clone_key'
(venv) root@1218450f6a25:/# echo $?
0
(venv) root@1218450f6a25:/# uv pip install dask-histogram
Resolved 12 packages in 380ms
Prepared 3 packages in 540ms
Installed 3 packages in 10ms
+ boost-histogram==1.5.0
+ dask-histogram==2024.3.0
+ numpy==2.1.1
(venv) root@1218450f6a25:/# python -c 'from dask.base import clone_key'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/venv/lib/python3.12/site-packages/dask/__init__.py", line 5, in <module>
from dask.base import (
File "/venv/lib/python3.12/site-packages/dask/base.py", line 1039, in <module>
from dask import multiprocessing as dask_multiprocessing
File "/venv/lib/python3.12/site-packages/dask/multiprocessing.py", line 19, in <module>
from dask.optimization import cull, fuse
File "/venv/lib/python3.12/site-packages/dask/optimization.py", line 10, in <module>
from dask._task_spec import GraphNode
File "/venv/lib/python3.12/site-packages/dask/_task_spec.py", line 90, in <module>
from dask.sizeof import sizeof
File "/venv/lib/python3.12/site-packages/dask/sizeof.py", line 318, in <module>
_register_entry_point_plugins()
File "/venv/lib/python3.12/site-packages/dask/sizeof.py", line 309, in _register_entry_point_plugins
registrar = entry_point.load()
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
module = import_module(match.group('module'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/dask_histogram/__init__.py", line 6, in <module>
from dask_histogram.core import (
File "/venv/lib/python3.12/site-packages/dask_histogram/core.py", line 13, in <module>
from dask.blockwise import BlockwiseDep, blockwise, fuse_roots, optimize_blockwise
File "/venv/lib/python3.12/site-packages/dask/blockwise.py", line 13, in <module>
from dask.base import clone_key, get_name_from_key, tokenize
ImportError: cannot import name 'clone_key' from partially initialized module 'dask.base' (most likely due to a circular import) (/venv/lib/python3.12/site-packages/dask/base.py)
(venv) root@1218450f6a25:/#
oh that's very weird... ok
I do see this in my environment with dask on main.
However, if I make a fresh environment, something like
$ conda create -n bit python==3.10
$ conda activate bit
$ pip install ".[complete]" # (in dask repo dir)
$ python
>>> import dask
is OK. If the same pip command is done in the dask-historgam repo, it fails.
If you install dask first, it imports. If you then install dask-historgam, it no longer does. The culprit is in pyproject.yaml:
[project.entry-points."dask.sizeof"]
dask_histogram = "dask_histogram.sizeof:register"
which causes the import of dask-histogram, importing dask while it is being imported. Why this changed I am not sure, but it should be possible to import the one module without importing the rest of dask-histogram anyway.
I believe it's this one: https://github.com/dask/dask/pull/11373/files
Thanks for investigating ! This is blocking us in bumping the dask ecosystem in nixpkgs.
Sorry, I was wrong, it was the following PR, perhaps these lines
Indeed, the following makes dask importable again. I'll post on their repo.
--- a/dask/optimization.py
+++ b/dask/optimization.py
@@ -7,8 +7,8 @@ from enum import Enum
from typing import Any
from dask import config, core, utils
-from dask._task_spec import GraphNode
+# from dask._task_spec import GraphNode
from dask.base import normalize_token, tokenize
from dask.core import (
flatten,
get_dependencies,
(GraphNode is used in the module, but only in places where it could be imported later)