lukas-blecher / LaTeX-OCR

pix2tex: Using a ViT to convert images of equations into LaTeX code.
https://lukas-blecher.github.io/LaTeX-OCR/
MIT License
12.7k stars 1.03k forks source link

AttributeError: module 'numpy' has no attribute 'float'. #360

Closed JianyuZhao612 closed 8 months ago

JianyuZhao612 commented 10 months ago

I'm working in Conda Environment with python version 3.8.16. After installing pytorch and pix2tex, I came across an error using pix2tex in command line:

Traceback (most recent call last): File "D:\Users\BY220037\Anaconda3\envs\test\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "D:\Users\BY220037\Anaconda3\envs\test\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "D:\Users\BY220037\Anaconda3\envs\test\Scripts\pix2tex.exe__main.py", line 7, in File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\pix2tex__main.py", line 27, in main from .cli import main File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\pix2tex\cli.py", line 1, in from pix2tex.dataset.transforms import test_transform File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\pix2tex\dataset\transforms.py", line 1, in import albumentations as alb File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\albumentations__init.py", line 5, in from .augmentations import File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\albumentations\augmentations__init__.py", line 8, in from .domain_adaptation import File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\albumentations\augmentations\domain_adaptation.py", line 6, in from qudida import DomainAdapter File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\qudida__init.py", line 6, in from sklearn.decomposition import PCA File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\sklearn\decomposition\init__.py", line 17, in from .dict_learning import dict_learning File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\sklearn\decomposition\dict_learning.py", line 4, in from . import _dict_learning File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\sklearn\decomposition_dict_learning.py", line 21, in from ..linear_model import Lasso, orthogonal_mp_gram, LassoLars, Lars File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\sklearn\linear_model\init__.py", line 12, in from ._least_angle import (Lars, LassoLars, lars_path, lars_path_gram, LarsCV, File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\sklearn\linear_model_least_angle.py", line 30, in method='lar', copy_X=True, eps=np.finfo(np.float).eps, File "D:\Users\BY220037\Anaconda3\envs\test\lib\site-packages\numpy\init.py", line 305, in getattr raise AttributeError(former_attrs[attr]) AttributeError: module 'numpy' has no attribute 'float'. np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

It seems that np.float is no longer in use in this numpy version(1.24.4). I tried to degrade numpy version to 1.19.5, but it's incompatible with pandas and scikit-image package:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. scikit-image 0.21.0 requires numpy>=1.21.1, but you have numpy 1.19.5 which is incompatible. pandas 2.0.3 requires numpy>=1.20.3; python_version < "3.10", but you have numpy 1.19.5 which is incompatible.

Does anyone have the same problem with me? How to solve this problem and make the package function normally?

guimath commented 8 months ago

np.float is indead depreacated in favor of np.float64. The error is happening in the sklearn library. My guess is you have an old version of scikit learn and you need to update it, so you should be able to correct the issue with : sudo pip install scikit-learn --upgrade or if you're using conda: conda update scikit-learn

JianyuZhao612 commented 8 months ago

np.float is indead depreacated in favor of np.float64. The error is happening in the sklearn library. My guess is you have an old version of scikit learn and you need to update it, so you should be able to correct the issue with : sudo pip install scikit-learn --upgrade or if you're using conda: conda update scikit-learn

Thanks a lot! After upgrading the scikit-learn package it functioned smoothly!