1

I installed pyodide.http but I cannot import it. What did I do wrong?

C:\Users\malik>pip install pyodide.http
Requirement already satisfied: pyodide.http in c:\users\malik\appdata\local\programs\python\python310\lib\site-packages (0.2.0)
WARNING: You are using pip version 22.0.4; however, version 22.3.1 is available.
You should consider upgrading via the 'C:\Users\malik\AppData\Local\Programs\Python\Python310\python.exe -m pip install --upgrade pip' command.

C:\Users\malik>python
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import  pyodide.http
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyodide'
>>>
  • I guess you mean `pyodide-http`. But this package doesn't install `pyodide`. That you have to install separately. – Clasherkasten Dec 23 '22 at 19:29
  • Trying to install `pyodide`, I get this error: ValueError: Pyodide is a Python distribution that runs in the browser or Node.js. It cannot be installed from PyPi. Do you guys know how can I install it? – modernAlchemist Dec 23 '22 at 19:44
  • Skimming the documentation, it seems like `pyodide` is a package that allows Python code to run in other environments (such as javascript). Python itself can (obviously) already run Python code, so installing it as a Python package would be useless. Why are you trying to do that? – John Gordon Dec 23 '22 at 19:50

1 Answers1

3

The pyodide Python module is a module that makes using Python easier in the browser and in particular includes the Python <-> Javascript Foreign Function Interface (FFI).

Outside of the browser, you can install it from the pyodide-py package,

pip install pyodide-py

However most of its functionality doesn't make sense outside of the browser (or Node.js runtime), so it is mostly intended to avoid import errors, in code that imports but does not directly need it.

Similarly pyodide-http is intended for monkeypatching request & HTTP client-related libraries for the browser. So I'm not sure why you are trying to install it outside of the browser.

If you are running in the browser, you would install pyodide-http with micropip rather than pip, and the pyodide module is included by default (in the Pyodide distribution).

rth
  • 10,680
  • 7
  • 53
  • 77