Search code examples
python-3.xnumpypip

Python ModuleNotFound error even module is installed


Add virtual environment for Python3 - python3 -m venv .venv.

Enter into this virtual environment - source .venv/bin/activate.

Add module numpy - python3 -m pip install numpy.

Then try to add module lap - python3 -m pip install lap. This command produces error - ModuleNotFoundError: No module named 'numpy' and few lines below - ImportError: lap requires numpy, please "pip install numpy".

What???

UPDATE

Usage of another virtual environment:

vbulash@vbulash-notebook:~/VSCode/recognition$ python3 -m venv .venv2
vbulash@vbulash-notebook:~/VSCode/recognition$ source .venv2/bin/activate
(.venv2) vbulash@vbulash-notebook:~/VSCode/recognition$ python3 -m pip install lap
Collecting lap
  Using cached lap-0.4.0.tar.gz (1.5 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      <string>:4: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
      Partial import of lap during the build process.
      Traceback (most recent call last):
        File "<string>", line 127, in get_numpy_status
      ModuleNotFoundError: No module named 'numpy'
      Traceback (most recent call last):
        File "/home/vbulash/VSCode/recognition/.venv2/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/vbulash/VSCode/recognition/.venv2/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/vbulash/VSCode/recognition/.venv2/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 149, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-1zmi7bid/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 366, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "/tmp/pip-build-env-1zmi7bid/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-1zmi7bid/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 236, in <module>
        File "<string>", line 220, in setup_package
      ImportError: lap requires numpy, please "pip install numpy".
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.


Solution

  • The bug was reported many times. Still no resolution. Last version lap 0.4.0 was released in 2018. Last commit was in 2022. The package seems outdated, buggy and abandoned.

    There is an advice to install lapx which is a fixed drop-in fork. So try

    pip install lapx