Skip to main content

Fixed: AttributeError: 'code' object has no attribute 'co_lnotab'

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

On Python 3.15, Dataset.map(..., num_proc=2) from Hugging Face's datasets library failed with AttributeError: 'code' object has no attribute 'co_lnotab'. The error comes from dill, which datasets uses to send your function to its worker processes: Python 3.15 removed co_lnotab, and the dill version datasets allows still reads it. Moving the project to Python 3.14 fixed it.

What I Was Doing​

I made a project with uv on Python 3.15.2, the newest Python, and added the datasets library:

Terminal
uv init --python 3.15 datasets-demo
cd datasets-demo
uv add datasets

uv add installed datasets 5.2.0, with dill 0.4.1 and multiprocess 0.70.19 among its dependencies. The script turns every word in a small dataset into capitals, with two processes working in parallel:

main.py
from datasets import Dataset


def shout(row):
return {"text": row["text"].upper()}


if __name__ == "__main__":
words = Dataset.from_dict({"text": ["hello", "world"]})
shouted = words.map(shout, num_proc=2)
print(shouted["text"])

num_proc=2 asks map to split the work between two processes. The if __name__ == "__main__": line is there because those processes start by loading this file again.

Terminal
uv run main.py

What I Expected​

Expected output
Column(['HELLO', 'WORLD'])

What I Got​

A long traceback, ending in:

Output (last lines)
obj.co_lnotab, # for < python 3.10 [not counted in args]
^^^^^^^^^^^^^
AttributeError: 'code' object has no attribute 'co_lnotab'. Did you mean '.co_linetable' instead of '.co_lnotab'?
when serializing tuple item 0
when serializing function reconstructor arguments
when serializing dict item 'function'
when serializing tuple item 2
when serializing tuple item 3

The last lines of the traceback: dill's save_code reading obj.co_lnotab, then AttributeError: 'code' object has no attribute 'co_lnotab'. Did you mean '.co_linetable' instead of '.co_lnotab'?, then lines saying when serializing tuple item 0, function reconstructor arguments and dict item 'function'.

The when serializing ... dict item 'function' lines say it failed while packing up my shout function, in dill/_dill.py, not in my code or in datasets.

What I Checked​

1. Without num_proc, it works​

I removed num_proc=2 from the map call and ran it again:

Terminal
uv run main.py
Output
Map: 100%|████████████████████████████████████████████████████| 2/2 [00:00<00:00, 593.13 examples/s]
Column(['HELLO', 'WORLD'])

The terminal after running main.py without num_proc: a Map progress bar at 100 percent, then Column(['HELLO', 'WORLD']).

So map itself works on 3.15. Only sending the function to other processes fails. (I put num_proc=2 back for the rest of this post.)

2. dill alone fails the same way​

The traceback ended in dill, so I asked dill to pack the smallest function there is:

Terminal
uv run python -c "import dill; dill.dumps(lambda: None)"
Output (last lines)
^^^^^^^^^^^^^
AttributeError: 'code' object has no attribute 'co_lnotab'. Did you mean '.co_linetable' instead of '.co_lnotab'?
when serializing tuple item 0
when serializing function reconstructor arguments

The terminal after dill.dumps(lambda: None): the same AttributeError: 'code' object has no attribute 'co_lnotab', when serializing a function.

The same error, without datasets involved at all. The versions in play:

Terminal
uv run python -c "import sys, datasets, dill; print(sys.version.split()[0], datasets.__version__, dill.__version__)"
Output
3.15.2 5.2.0 0.4.1

3. What the documentation and the packages say​

  • Python 3.15 removed the attribute. What's New in Python 3.15 lists: "Removed codeobject.co_lnotab from types.CodeType, deprecated since Python 3.12 by PEP 626."
  • datasets doesn't list Python 3.15 yet. Its installation guide says "Datasets is tested on Python 3.10+", and datasets 5.2.0's package lists Python 3.10 to 3.14 as supported versions.
  • datasets pins dill below 0.4.2. Its setup.py requires dill>=0.3.0,<0.4.2 and multiprocess<0.70.20. dill 0.4.1 is the newest release, and it still reads co_lnotab.

Why It Happens​

datasets hashes your function itself, with code that was already updated for newer Pythons, which is why a single-process map works. With num_proc, it hands the function to multiprocess, which sends it to the worker processes using dill's own pickler, and dill 0.4.1 reads obj.co_lnotab, which no longer exists in Python 3.15.

dill has already changed this on its development branch, but that change isn't in a release yet, and datasets' dill<0.4.2 pin would keep the next release out anyway. I reported it to datasets as issue #9312, so the pins can move when dill and multiprocess release their Python 3.15 support.

The Fix​

Use Python 3.14, the newest version datasets supports. My first try was to pin it directly:

Terminal
uv python pin 3.14
Output
error: The requested Python version `3.14` is incompatible with the project `requires-python` value of `>=3.15`.

The terminal after uv python pin 3.14: error: The requested Python version 3.14 is incompatible with the project requires-python value of >=3.15.

uv refused: uv init --python 3.15 had written requires-python = ">=3.15" into pyproject.toml. So first change that line, to say the project needs 3.14 and doesn't work on 3.15 yet:

pyproject.toml
requires-python = ">=3.14,<3.15"

The <3.15 keeps anyone who installs the project off Python 3.15 until it works there. Then pin again:

Terminal
uv python pin 3.14
Output
Updated `.python-version` from `3.15` -> `3.14`

The terminal after the second uv python pin 3.14: Updated .python-version from 3.15 -> 3.14.

How to Change a uv Project's Python Version with uv python pin explains both commands in detail.

After the Fix​

Terminal
uv run main.py
Output
Using CPython 3.14.10
Removed virtual environment at: .venv
Creating virtual environment at: .venv
warning: Resolving despite existing lockfile due to fork markers being disjoint with `requires-python`: `python_full_version >= '3.15'` vs `python_full_version == '3.14.*'`
Built datasets-demo @ file:///Users/you/source/datasets-demo
Installed 25 packages in 110ms
Map (num_proc=2): 100%|████████████████████████████████████████| 2/2 [00:00<00:00, 16.45 examples/s]
Column(['HELLO', 'WORLD'])

The terminal after the fix: uv used CPython 3.14.10, recreated .venv and installed 25 packages, the Map (num_proc=2) bar reached 100 percent, and the script printed Column(['HELLO', 'WORLD']).

uv saw the new Python version, rebuilt the environment on 3.14.10, and map ran with two processes. Its first line is a warning, not an error: the lock file had been made for >=3.15, so uv worked out the packages again for 3.14. The versions now:

Terminal
uv run python -c "import sys, datasets, dill; print(sys.version.split()[0], datasets.__version__, dill.__version__)"
Output
3.14.10 5.2.0 0.4.1

Same datasets, same dill; only Python changed. The commands work unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Pinning 3.14 before changing requires-pythonerror: The requested Python version `3.14` is incompatible with the project `requires-python` value of `>=3.15`.Change requires-python first
Removing num_proc to make the error go awaymap works, but on one process: slower on big datasets, and the project still sits on a Python its libraries don't supportMove to Python 3.14
Installing a newer dill by handdatasets requires dill<0.4.2, so uv won't install a version outside that rangeWait for datasets to allow it; use 3.14 until then

Troubleshooting​

SymptomLikely causeFix
AttributeError: 'code' object has no attribute 'co_lnotab' from dill/_dill.pyPython 3.15 with dill 0.4.1Use Python 3.14
The same error from another library that uses dillThe same dill versionThe same fix, or that library's update

FAQ​

When will Python 3.15 work?​

When dill and multiprocess release their Python 3.15 changes, and datasets raises its version limits to allow them. Issue #9312 tracks it on the datasets side.

Do I lose anything with Python 3.14?​

Only Python 3.15's new features. Everything in this post's stack supports 3.14.

Conclusion​

AttributeError: 'code' object has no attribute 'co_lnotab' came from dill 0.4.1, which datasets 5.2.0 uses to send functions to worker processes, on Python 3.15, which removed co_lnotab. With requires-python = ">=3.14,<3.15" and uv python pin 3.14, the same code ran on Python 3.14.10 with two processes.

Additional Resources​