pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.38k stars 1.16k forks source link

[BUG] Module Not Found for Python 3.12. It works in Python 3.10 for Setuptools version 65.5.0. #4425

Open brightlightkim opened 2 weeks ago

brightlightkim commented 2 weeks ago

setuptools version

70.0.0

Python version

Python 3.12

OS

Mac M2 Pro Max, Mac M1 Pro

Additional environment information

[metadata] name = backend description = backend author = Kimchi platforms = unix, linux, osx, win32 classifiers = Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 version = 0.1.0

[options] packages = find: install_requires = requests >= 2 python_requires = >=3.10

requirements.txt file

aiohttp==3.9.5 asyncio==3.4.3 boto3==1.34.122 fastapi==0.111.0 firebase-admin==6.5.0 google-cloud-storage==2.17.0 httpx==0.27.0 poetry==1.1.12 pre-commit==3.7.1 pytest==8.2.2 pytest==8.2.2 pytest-mock==3.14.0 requests setuptools==70.0.0 uvicorn==0.30.1 wheel==0.43.0 gemini_webapi==1.5.1

Description

File Name: generate_background.py

from api.controllers.helpers import ( generate_background_aws, generate_background_firebase, generate_background_google, )

This returns the error that ModuleNotFoundError: No module named 'api'

File Path: src --api ----controllers ------helpers --------init.py --------aws.py --------firebase.py --------gcs.py ------generate_background.py

In the helpers folder, The init file looks like

File Name: init.py

from .firebase import generate_background_firebase from .gcs import generate_background_google

all = [ "generate_background_aws", "generate_background_firebase", "generate_background_google", ]

And the aws.py file has this kind of function:

File Name: aws

async def generate_background_aws()

Please let me know if any of the change I should make to make this work. Our team is wondering if we should downgrade our python version to 3.10 which worked for one member.

Expected behavior

We should be able to import the local modules correctly.

How to Reproduce

Just try to run the file after making the similar file and path structure. It returns an error....

Output

Process SpawnProcess-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/env/lib/python3.12/site-packages/uvicorn/_subprocess.py", line 80, in subprocess_started
    target(sockets=sockets)
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/env/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/env/lib/python3.12/site-packages/uvicorn/server.py", line 69, in serve
    await self._serve(sockets)
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/env/lib/python3.12/site-packages/uvicorn/server.py", line 76, in _serve
    config.load()
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/env/lib/python3.12/site-packages/uvicorn/config.py", line 434, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/env/lib/python3.12/site-packages/uvicorn/importer.py", line 22, in import_from_string
    raise exc from None
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/env/lib/python3.12/site-packages/uvicorn/importer.py", line 19, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/src/main.py", line 2, in <module>
    from .api.routes import image_router, text_router
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/src/api/__init__.py", line 1, in <module>
    from . import controllers, routes, utils
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/src/api/controllers/__init__.py", line 2, in <module>
    from .generate_background import generate_background
  File "/Users/taeyangkim/Dev/ai-video-gen/backend/src/api/controllers/generate_background.py", line 8, in <module>
    from helpers.aws import generate_background_aws
ModuleNotFoundError: No module named 'helpers'
abravalheri commented 2 weeks ago

Hi @brightlightkim , isn't the a problem because the way you wrote the import statement (from helpers.aws import generate_background_aws)? Shouldn't it be a relative import instead of the absolute import?

The other thing I can see that you are using find: in setup.cfg, but some of your folders don't contain an __init__.py file.

aignacio commented 2 weeks ago

Hey @abravalheri,

I'm having a similar issue with python-3.12 only with my package. While running on 3.8/9/10/11, I can build my package and run my tests, please check the log below.

Package: cocotbext-ahb Setup file: setup.py

Ps.: I modified my local noxfile.py to include 3.12 in the run session.

root@bbfc4b27bcad:/cocotbext-ahb# nox -s run-3.12 -- -k "test_ahb_lite_sram.py"
nox > Running session run-3.12
nox > Re-using existing virtual environment at .nox/run-3-12.
nox > python -m pip install pytest pytest-xdist pytest-sugar pytest-cov pytest-split cocotb-bus==0.2.1 cocotb-test==0.2.4 'cocotb>=1.8.0'
nox > python -m pip install -e .
nox > Command python -m pip install -e . failed with exit code 1:
Obtaining file:///cocotbext-ahb
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Checking if build backend supports build_editable: started
  Checking if build backend supports build_editable: finished with status 'done'
  Getting requirements to build editable: started
  Getting requirements to build editable: finished with status 'error'
  error: subprocess-exited-with-error

  × Getting requirements to build editable did not run successfully.
  │ exit code: 1
  ╰─> [27 lines of output]
      Traceback (most recent call last):
        File "/cocotbext-ahb/.nox/run-3-12/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/cocotbext-ahb/.nox/run-3-12/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 "/cocotbext-ahb/.nox/run-3-12/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 132, in get_requires_for_build_editable
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-px4dvd0v/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 448, in get_requires_for_build_editable
          return self.get_requires_for_build_wheel(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-px4dvd0v/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-px4dvd0v/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-px4dvd0v/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-px4dvd0v/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 4, in <module>
        File "/cocotbext-ahb/cocotbext/ahb/__init__.py", line 16, in <module>
          from .ahb_master import AHBLiteMaster, AHBMaster
        File "/cocotbext-ahb/cocotbext/ahb/ahb_master.py", line 10, in <module>
          import cocotb
      ModuleNotFoundError: No module named 'cocotb'
      [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 editable 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.
nox > Session run-3.12 failed.
root@bbfc4b27bcad:/cocotbext-ahb#

Version

Package      Version                                                                                                                                                                          │        modified:   cocotbext/ahb/utils.py
------------ ---------                                                                                                                                                                        │        deleted:    monitor.py
argcomplete  3.4.0                                                                                                                                                                            │        modified:   noxfile.py
colorlog     6.8.2                                                                                                                                                                            │        modified:   tests/test_ahb_lite_sram.py
distlib      0.3.8                                                                                                                                                                            │
filelock     3.15.1                                                                                                                                                                           │no changes added to commit (use "git add" and/or "git commit -a")
nox          2024.4.15                                                                                                                                                                        │❯ rm -rf log.txt
packaging    24.1                                                                                                                                                                             │╭─     ~/projects/cocotbext-ahb  on    master *3 !5 ······················
pip          24.0                                                                                                                                                                             │················ ✔  at 06:45:25 pm 
platformdirs 4.2.2                                                                                                                                                                            │╭─     ~/projects/cocotbext-ahb  on    master *3 !5 ······················
setuptools   68.1.2                                                                                                                                                                           │··············· ✔  at 06:45:25 pm   ─╮
virtualenv   20.26.2                                                                                                                                                                          │╭─     ~/projects/cocotbext-ahb  on    master *3 !5 ····· ✔  at 06:45:25
wheel        0.42.0
abravalheri commented 2 weeks ago

Hi @aignacio , I don't think your problem is the same as discussed in this issue.

It seems that you are trying to perform an import statement during build time without defining a build time dependency in a way that pip understands (i.e. via pyproject.toml).

You probably forgot to factor in the "build isolation" behaviour that sometimes is triggered by pip (don't ask me when, it is internal pip heuristics, maybe it is described in pip's docs...).

In "build isolation" pip completely ignore everything you have installed and create a brand new throw away environment just for the build.

Please revise your setup/CI to make sure you account for that. After that if you still have problems that are associated with setuptools behaviour, please open a separated issue.

aignacio commented 2 weeks ago

pyproject.toml

Hi @aignacio , I don't think your problem is the same as discussed in this issue.

It seems that you are trying to perform an import statement during build time without defining a build time dependency in a way that pip understands (i.e. via pyproject.toml).

You probably forgot to factor in the "build isolation" behaviour that sometimes is triggered by pip (don't ask me when, it is internal pip heuristics, maybe it is described in pip's docs...).

In "build isolation" pip completely ignore everything you have installed and create a brand new throw away environment just for the build.

Please revise your setup/CI to make sure you account for that. After that if you still have problems that are associated with setuptools behaviour, please open a separated issue.

Thanks @abravalheri, that solved the problem, It was a miss the pyproject.toml indeed! I just wonder now how it is working for previous python versions...

abravalheri commented 2 weeks ago

the "build isolation" behaviour that sometimes is triggered by pip (don't ask me when, it is internal pip heuristics, maybe it is described in pip's docs...).

☝️