furqan4545 / handwritten_text_detection_and_recognition

This repo contains the code for hand written text detection and recognition model using computer vision
MIT License
23 stars 25 forks source link

pytest ModuleNotFoundError: No module named 'numpy' #3

Open jhalbrecht opened 1 week ago

jhalbrecht commented 1 week ago

I invoked pytest from the "handwritten_text_detection_and_recognition/tests" directory. I received this error.

I tried pip install numpy and pip install NumPy got "Requirement already satisfied: NumPy in /home/jeffa/ocr/lib/python3.11/site-packages (2.0.0)"

(ocr) jeffa@ocr:~/dev/handwritten_text_detection_and_recognition/tests$ pytest
=================================================================== test session starts ====================================================================platform linux -- Python 3.11.2, pytest-7.2.1, pluggy-1.0.0+repack
rootdir: /home/jeffa/dev/handwritten_text_detection_and_recognition
collected 0 items / 1 error
                                                                                                                                                            ========================================================================== ERRORS ==========================================================================_________________________________________________________ ERROR collecting tests/test_synthetic.py _________________________________________________________ImportError while importing test module '/home/jeffa/dev/handwritten_text_detection_and_recognition/tests/test_synthetic.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_synthetic.py:1: in <module>
    import numpy as np
E   ModuleNotFoundError: No module named 'numpy'
================================================================= short test summary info ==================================================================ERROR test_synthetic.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================== 1 error in 0.03s =====================================================================(ocr) jeffa@ocr:~/dev/handwritten_text_detection_and_recognition/tests$ pip install NumPy
Requirement already satisfied: NumPy in /home/jeffa/ocr/lib/python3.11/site-packages (2.0.0)
(ocr) jeffa@ocr:~/dev/handwritten_text_detection_and_recognition/tests$
jhalbrecht commented 1 week ago

Although pytest failed I went on to try some examples. I noticed pip install -r requirements.txt after running that /tests/pytest still fails. I went to the /examples and ran python main.py resulting in this output;

(ocr) jeffa@ocr:~/dev/handwritten_text_detection_and_recognition/examples$ python main.py
File path:  ../data/page
Processing file ../data/page/r06-137.png
Traceback (most recent call last):
  File "/home/jeffa/dev/handwritten_text_detection_and_recognition/examples/main.py", line 96, in <module>
    save_image_names_to_text_files()
  File "/home/jeffa/dev/handwritten_text_detection_and_recognition/examples/main.py", line 46, in save_image_names_to_text_files
    detections = detect(img,
                 ^^^^^^^^^^^
  File "/home/jeffa/ocr/lib/python3.11/site-packages/word_detector/__init__.py", line 47, in detect
    kernel = _compute_kernel(kernel_size, sigma, theta)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jeffa/ocr/lib/python3.11/site-packages/word_detector/__init__.py", line 84, in _compute_kernel
    x_term = (x ** 2 - sigma_x ** 2) / (2 * np.math.pi * sigma_x ** 5 * sigma_y)
                                            ^^^^^^^
  File "/home/jeffa/ocr/lib/python3.11/site-packages/numpy/__init__.py", line 410, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'math'. Did you mean: 'emath'?
(ocr) jeffa@ocr:~/dev/handwritten_text_detection_and_recognition/examples$ 
jhalbrecht commented 1 week ago

In "/home/jeffa/ocr/lib/python3.11/site-packages/word_detector/init.py" I changed lines 84,85 for pi s/np.math.pi/np.pi/ Then I ran tests again, which appear to pass.

(ocr) jeffa@ocr:~/dev/handwritten_text_detection_and_recognition/tests$ pytest
===================================================================== test session starts ======================================================================platform linux -- Python 3.11.2, pytest-8.2.2, pluggy-1.5.0
rootdir: /home/jeffa/dev/handwritten_text_detection_and_recognition
collected 1 item

test_synthetic.py .                                                                                                                                      [100%]

====================================================================== 1 passed in 0.59s =======================================================================

Next I tried python main.py in /examples again failing as;

(ocr) jeffa@ocr:~/dev/handwritten_text_detection_and_recognition/examples$ python main.py
File path:  ../data/page
Processing file ../data/page/r06-137.png
Traceback (most recent call last):
  File "/home/jeffa/dev/handwritten_text_detection_and_recognition/examples/main.py", line 96, in <module>
    save_image_names_to_text_files()
  File "/home/jeffa/dev/handwritten_text_detection_and_recognition/examples/main.py", line 58, in save_image_names_to_text_files
    colors = plt.cm.get_cmap('rainbow', num_colors)
             ^^^^^^^^^^^^^^^
AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'
(ocr) jeffa@ocr:~/dev/handwritten_text_detection_and_recognition/examples$