Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multipart ModuleNotFoundError by renaming import to python_multipart #10188

Merged
merged 6 commits into from
Dec 12, 2024

Conversation

archiloque
Copy link
Contributor

(I'm not experienced about Python's dependency and packaging, sorry if my analysis or suggestions are wrong)

I'm using Gradio on a project that depends on https://pypi.org/project/python-multipart/ through Gradio and https://pypi.org/project/multipart/ through another dependecy.

I tried to update the Gradio version to 5.8.0 and now I get an error at startup.

File "/opt/XXXX/gradio_interface.py", line 5, in <module>
import gradio as gr
File "/root/poetry.cache/virtualenvs/non-package-mode-KSsrRO-R-py3.12/lib/python3.12/site-packages/gradio/__init__.py", line 3, in <module>
import gradio._simple_templates
File "/root/poetry.cache/virtualenvs/non-package-mode-KSsrRO-R-py3.12/lib/python3.12/site-packages/gradio/_simple_templates/__init__.py", line 1, in <module>
from .simpledropdown import SimpleDropdown
File "/root/poetry.cache/virtualenvs/non-package-mode-KSsrRO-R-py3.12/lib/python3.12/site-packages/gradio/_simple_templates/simpledropdown.py", line 7, in <module>
from gradio.components.base import Component, FormComponent
File "/root/poetry.cache/virtualenvs/non-package-mode-KSsrRO-R-py3.12/lib/python3.12/site-packages/gradio/components/__init__.py", line 1, in <module>
from gradio.components.annotated_image import AnnotatedImage
File "/root/poetry.cache/virtualenvs/non-package-mode-KSsrRO-R-py3.12/lib/python3.12/site-packages/gradio/components/annotated_image.py", line 14, in <module>
from gradio import processing_utils, utils
File "/root/poetry.cache/virtualenvs/non-package-mode-KSsrRO-R-py3.12/lib/python3.12/site-packages/gradio/processing_utils.py", line 33, in <module>
from gradio.route_utils import API_PREFIX
File "/root/poetry.cache/virtualenvs/non-package-mode-KSsrRO-R-py3.12/lib/python3.12/site-packages/gradio/route_utils.py", line 36, in <module>
from multipart.multipart import parse_options_header
ModuleNotFoundError: No module named 'multipart.multipart'; 'multipart' is not a package

From Kludex/python-multipart#180 (comment) , my understanding is that the issue comes from the fact that python-multipart changed their package name to python-multipart with some compatibility, but the compatibility, but it doesn't work in my case.

Since Gradio depends on python-multipart>=0.0.18, the code can be updated to use the new package name.

I've tried to run the Gradio tests localy and they don't all pass on main even when using dev containers, but I don't see any new test failure after the change.

As the fix is two lines of import, I feel that "please create an issue before you create this PR, unless the fix is very small" applies to this case.

Thanks !

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 12, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/e364074fae7fee0a4afdd6c87de272f74f1fafbd/gradio-5.8.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@e364074fae7fee0a4afdd6c87de272f74f1fafbd#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/e364074fae7fee0a4afdd6c87de272f74f1fafbd/gradio-client-1.8.0.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/e364074fae7fee0a4afdd6c87de272f74f1fafbd/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 12, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix multipart ModuleNotFoundError by renaming import to python_multipart

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs
Copy link
Member

Thanks @archiloque. You're right in making this change. It seems to be a consequence of this PR. We should rename the multipart import to python_multipart everywhere. I'll push a couple of other changes to this PR and then we can merge.

@abidlabs abidlabs added the v: patch A change that requires a patch release label Dec 12, 2024
@abidlabs abidlabs changed the title Fix ModuleNotFoundError: No module named 'multipart.multipart'; 'multipart' is not a package Fix 'multipart' ModuleNotFoundError by renaming import to python_multipart Dec 12, 2024
@abidlabs abidlabs changed the title Fix 'multipart' ModuleNotFoundError by renaming import to python_multipart Fix multipart ModuleNotFoundError by renaming import to python_multipart Dec 12, 2024
@abidlabs
Copy link
Member

Merging, thanks again @archiloque!

@abidlabs abidlabs merged commit 22fe4ce into gradio-app:main Dec 12, 2024
22 checks passed
@archiloque archiloque deleted the Fix-ModuleNotFoundError branch December 13, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v: patch A change that requires a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants