solara icon indicating copy to clipboard operation
solara copied to clipboard

ImportError: cannot import name 'LOOP_CHOICES' from 'uvicorn.main' when using Python 3.14

Open EwoutH opened this issue 1 month ago • 2 comments

Solara fails to start on Python 3.14 due to importing deprecated LOOP_CHOICES constant from uvicorn that has been removed.

Expected behavior

Solara should successfully import and run on Python 3.14 without import errors from uvicorn dependencies.

Current behavior

When running Solara on Python 3.14, the application fails to start with an ImportError:

Traceback (most recent call last):
 File "/opt/hostedtoolcache/Python/3.14.0/x64/bin/solara", line 3, in <module>
 from solara.__main__ import main
 File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/solara/__main__.py", line 16, in <module>
 from uvicorn.main import LEVEL_CHOICES, LOOP_CHOICES
ImportError: cannot import name 'LOOP_CHOICES' from 'uvicorn.main' (/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/uvicorn/main.py)

The issue is that LOOP_CHOICES has been removed from uvicorn's public API in recent versions.

Steps to reproduce the problem

  1. Install Python 3.14
  2. Install Solara: pip install solara
  3. Run any Solara command: solara run app.py
  4. Observe the ImportError on startup

Specifications

  • Solara Version: master
  • Platform: Linux (GitHub Actions hosted runner)
  • Affected Python Versions: Python 3.14.0

Potential solution

Update solara/__main__.py line 16 to handle the missing LOOP_CHOICES import:

from uvicorn.main import LEVEL_CHOICES

# LOOP_CHOICES was removed from uvicorn, define it locally for backward compatibility
try:
    from uvicorn.main import LOOP_CHOICES
except ImportError:
    # Fallback for newer uvicorn versions
    LOOP_CHOICES = click.Choice(["auto", "asyncio", "uvloop"])

EwoutH avatar Oct 08 '25 10:10 EwoutH

Same issue with other Python versions: https://github.com/widgetti/solara/issues/1101 Pinning uvicorn<0.30 resolves the issue.

egormkn avatar Oct 09 '25 11:10 egormkn

actually uvicorn==0.35 is the last supported version apparently.. above that things break, although I have found a way to bypass the issue with the latest version of uvicorn . If anyone is interested, i can share

JovanVeljanoski avatar Oct 16 '25 07:10 JovanVeljanoski

Fixed in #1113

maartenbreddels avatar Nov 06 '25 15:11 maartenbreddels