ANP-Granular / ParticleTracking

Library and GUI for tracking (rod-like) particles on camera images in 2D and 3D
https://particletracking.readthedocs.io/en/latest/
GNU General Public License v3.0
2 stars 2 forks source link

Numpy not detected when installing from source #90

Closed merrygoat closed 4 months ago

merrygoat commented 5 months ago

After RodTracking is installed from source on Windows, an error is given when trying to run a detection that indicates that PyTorch cannot find NumPy

To Reproduce git clone https://github.com/ANP-Granular/ParticleTracking.git . python -m venv venv .\venv\Scripts\activate cd .\RodTracker\ pip install -e . rodtracker

In GUI -> Load images -> Select \RodTracker\src\RodTracker\resources\example_data\images\gp3 In Detection Tab click "Use Example Model" In detection Tab click "Detect"

"An Unexpected Error Occurred" dialog is shown.

Additional context pip list shows that numpy 2.0.0 is present in the venv

Logs Attached because markdown mangles the formatting: log.txt

merrygoat commented 5 months ago

I see now that this seems to be related to an incompatibility between Pytorch and Numpy 2.0.

In stdout for the GUI I see:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

And a traceback which points to torch.

Solution is pip install numpy<2.

This: https://github.com/pytorch/pytorch/issues/107302 seems to suggest pytorch>2.2 should be fine with numpy 2 and my venv has torch 2.3.1, so I don't know what is going on there.

Perhaps just add a numpy<2 restriction to pyproject.toml.

a-niem commented 5 months ago

It appears that the issue stems from the installed version of torchvision being <0.19 (see this issue). As suggested, I've added the additional version restriction in the pyproject.toml.

merrygoat commented 4 months ago

Just installed develop branch from source and that worked well.