Skip to content

[BUG] ModuleNotFoundError when importing additional local scripts in setup.py #3939

@kdschlosser

Description

@kdschlosser

setuptools version

67.8.0

Python version

3.8, 3.9, 3.10, 3.11

OS

Windows, Linux, OSX

Additional environment information

No response

Description

when installing using pip install . for doing a local install or when installing an sdist from pypi using pip install {library_name} under linux if there are additional imports in setup.py for local modules to setup.py the build fails with ModuleNotFound.

On Windows I am able to work around this problem by explicitly adding the parent folder to setup.py to sys.path. this however does not work for Linux.

Expected behavior

To have the installation work properly

How to Reproduce

I have attached an example package that produces the error. Extract the attached file and go into the folder where the setup.py is and use pip install . you will see the error.

pip_failure.zip

Output

****************\pip_failure>pip install .
Processing ****************\pip_failure
  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
  ╰─> [18 lines of output]
      Traceback (most recent call last):
        File "\python\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "\python\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "\python\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "********\AppData\Local\Temp\pip-build-env-ztw59mba\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "********\AppData\Local\Temp\pip-build-env-ztw59mba\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in _get_build_requires
          self.run_setup()
        File "********\AppData\Local\Temp\pip-build-env-ztw59mba\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup
          exec(code, locals())
        File "<string>", line 5, in <module>
      ModuleNotFoundError: No module named 'some_module'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ReproIssues that need a reproducible example.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions