When using Python 3.11.8, I get ModuleNotFoundError: No module named 'requests'

Hi all,
I am urgently in need of help. I get the following stack trace when running

pip install -r requirements.txt
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [26 lines of output]
      Traceback (most recent call last):
        File "xxx/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
        File "xxx/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "xxx/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/private/var/folders/96/llwnx0n57vd17gtfyw124z500000gq/T/pip-build-env-l77c99nj/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/private/var/folders/96/llwnx0n57vd17gtfyw124z500000gq/T/pip-build-env-l77c99nj/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
        File "/private/var/folders/96/llwnx0n57vd17gtfyw124z500000gq/T/pip-build-env-l77c99nj/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 487, in run_setup
        File "/private/var/folders/96/llwnx0n57vd17gtfyw124z500000gq/T/pip-build-env-l77c99nj/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 6, in <module>
        File "/private/var/folders/96/llwnx0n57vd17gtfyw124z500000gq/T/pip-install-_yo6mvpx/khoros_524603794daf41a38f0d84ef85bee8be/khoros/__init__.py", line 13, in <module>
          from .core import Khoros
        File "/private/var/folders/96/llwnx0n57vd17gtfyw124z500000gq/T/pip-install-_yo6mvpx/khoros_524603794daf41a38f0d84ef85bee8be/khoros/core.py", line 17, in <module>
          from . import auth, errors, liql, api
        File "/private/var/folders/96/llwnx0n57vd17gtfyw124z500000gq/T/pip-install-_yo6mvpx/khoros_524603794daf41a38f0d84ef85bee8be/khoros/auth.py", line 12, in <module>
          import requests
      ModuleNotFoundError: No module named 'requests'

I have activated venv and did a fresh pip install but I still get this error. I tried running

python --version which shows 3.11.8


python -m pip install requests which ran successfully


The version of khoros you are trying to install is badly behaved and one of the changes to python’s install process in the last few years broke it. I would suggest to try and use a different, newer version. From what I can tell, the versions starting at 4.0 should work.

What might also work is running pip install with --no-build-isolation, but this is more a guess.

1 Like

Thanks a lot @MegaIng, it worked like a charm, (the --no-build-isolation didn’t work and wasn’t needed). I was understanding it as a global module import error and not specific to Khoros and as luck would have it, it was the last dependency mentioned in my requirements.txt. Thanks once again.


When contemporary versions of Pip try to install something from source, they default to setting up a temporary virtual environment (“isolated build environment”) for that build process. (This is a separate venv from anything that you created.) But in older versions of the package, Khoros’s setup.py tries to import from its own code in order to detect its own version number - and the top-of-file imports indirectly, inadvertently try to import the Requests library (which is only needed to run the code, not to install it).

To fix the problem from here, you would need to first install Requests into that same venv, and then install Khoros without build isolation (so that Pip instead uses its current environment, which now has Requests in it). But really the problem is with Khoros. Since this is a pure-Python project, ideally it wouldn’t use setup.py at all [1], and ideally it would just be distributed as a wheel anyway.

  1. even though this is completely supported and will be for a very long time; it’s not as if Pip can detect ahead of time whether there’s anything that really needs to be “built”, and there isn’t really a simpler, standard mechanism to handle “just discover the version number dynamically and do everything else in pyproject.toml↩︎

1 Like