bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.33k stars 1.46k forks source link

Unable to import extensions in Python 3.12 / ModuleNotFoundError #1430

Open brentvollebregt opened 9 months ago

brentvollebregt commented 9 months ago

After upgrading to Python 3.12, importing an extension, for example from bottle.ext.websocket import websocket, now gives the following error:

Traceback (most recent call last):
  File "C:\...\test.py", line 1, in <module>
    from bottle.ext.websocket import websocket
ModuleNotFoundError: No module named 'bottle.ext.websocket'

My environment:

Reproduction:

  1. Install dependencies: pip install bottle==0.12.25 bottle-websocket==0.2.9
  2. Run script:
    from bottle.ext.websocket import websocket

Investigation / Potential Solution:

I see this error does not occur on master but it does on the release-0.12 branch / 0.12.25 tag. Using the changes from https://github.com/bottlepy/bottle/commit/ca6762c559c5e71e0dff71dc97eb4c6b3ed9bbcd that are currently on master seems to fix this issue.

brentvollebregt commented 8 months ago

To add more info to this, I see support for the find_module API has been removed in Python 3.12 as noted in the changelog here:

Support for find_loader() and find_module() APIs have been removed. (Contributed by Barry Warsaw in gh-98040.)

The changelog recommends using find_spec() instead.