kolofordjango / kolo

See everything happening in your running Django app. All without leaving VSCode
https://kolo.app
486 stars 14 forks source link

kolo run import numpy fails #62

Closed zacps closed 1 year ago

zacps commented 1 year ago
# reproduce.py
# kolo==2.11.0 (latest)
# numpy==1.25.0 (latest)
import numpy
kolo run reproduce.py
Traceback (most recent call last):
  File "/code/.local/bin/kolo", line 8, in <module>
    sys.exit(cli())
  File "/code/.local/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/code/.local/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/code/.local/lib/python3.10/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/code/.local/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/code/.local/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/code/.local/lib/python3.10/site-packages/kolo/__main__.py", line 145, in run
    profile_path(profiler, path)
  File "/code/.local/lib/python3.10/site-packages/kolo/__main__.py", line 75, in profile_path
    run_path(path, run_name="__main__")
  File "/usr/lib/python3.10/runpy.py", line 289, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "reproduce.py", line 1, in <module>
    import numpy
  File "/code/.local/lib/python3.10/site-packages/numpy/__init__.py", line 151, in <module>
    from . import random
  File "/code/.local/lib/python3.10/site-packages/numpy/random/__init__.py", line 180, in <module>
    from . import _pickle
  File "/code/.local/lib/python3.10/site-packages/numpy/random/_pickle.py", line 1, in <module>
    from .mtrand import RandomState
  File "mtrand.pyx", line 4651, in init numpy.random.mtrand
  File "mtrand.pyx", line 182, in numpy.random.mtrand.RandomState.__init__
  File "_mt19937.pyx", line 129, in numpy.random._mt19937.MT19937.__init__
  File "bit_generator.pyx", line 517, in numpy.random.bit_generator.BitGenerator.__init__
  File "bit_generator.pyx", line 307, in numpy.random.bit_generator.SeedSequence.__init__
  File "bit_generator.pyx", line 392, in numpy.random.bit_generator.SeedSequence.get_assembled_entropy
FileNotFoundError: No such file or directory (os error 2)

Running without kolo works as expected.

LilyFoote commented 1 year ago

@zacps I can't reproduce this. Can you share more information about your environment?

What operating system are you using? What version of python are you using? Are you using a virtualenv? Do you have any other packages installed?

zacps commented 1 year ago

@LilyFoote It seems like the issue only occurs when pandas is installed as well, minimal reproduction:

FROM ubuntu:22.04

RUN apt update && \
    apt install -y \
        python3 \
        python3-pip

RUN pip install \
        kolo==2.11.0 \
        numpy==1.24.3 \
        pandas==2.0.2

COPY <<EOF repro.py
import numpy
print("Succeeded")
EOF

ENTRYPOINT [ "kolo" ]
CMD ["run", "repro.py"]
docker build -t kolo-repro . && docker run kolo-repro
LilyFoote commented 1 year ago

@zacps I did manage to replicate this with numpy 1.24.3 and 1.24.4. Installing 1.25.0 fixed it for me. I tried bisecting numpy and found https://github.com/seberg/numpy/commit/60a858a372b14b73547baacf4a472eccfade1073, but I don't see why that would be relevant.

zacps commented 1 year ago

Neither do I. I think my first inclination would be to attach a debugger and step through to see exactly where that traceback comes from. I'm not sure I believe it, certainly the pyx frames don't have sensible line numbers at the very least.

Unfortunately that's probably past what I can justifiably do on the clock!

LilyFoote commented 1 year ago

I've tracked down the bug and I'll release the fix today. Thanks for the report!