micropip
micropip copied to clipboard
Optional dependency ignored by micropip
🐛 Bug
When install optional dependency micropip.install(['pydantic[email]']) (defined here), however, installing the dependency manually works.
To Reproduce
Go to https://pyodide.org/en/stable/console.html
Welcome to the Pyodide terminal emulator 🐍
Python 3.11.2 (main, Jun 18 2023 00:11:52) on WebAssembly/Emscripten
Type "help", "copyright", "credits" or "license" for more information.
>>> import micropip
await micropip.install(['pydantic[email]'])
import email_validator
Traceback (most recent call last):
File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'email_validator'
>>> import micropip
await micropip.install(['pydantic[email]', 'email-validator>=2.0.0'])
import email_validator
>>>
Expected behavior
It should work by just doing micropip.install(['pydantic[email]']).
Environment
>>> import pyodide
>>> pyodide.__version__
'0.23.3'
I think it's because pydantic is built as part of the main Pyodide distribution here which doesn't have the notion of optional dependencies. Micropip loads it via loadPyodide. For packages installed from PyPI it should handle the optional dependencies correctly.
So I agree it's not an ideal behavior, but I'm not sure what we can do about it. Supporting extra dependencies in the main distribution would be rather difficult (the same way as conda doesn't support them).