0

每当我尝试在 pyodide 中安装任何模块时,我都会遇到“ImportError: cannot import name 'fetch' from 'js' (unknown location)”的错误。最初,我尝试了以下代码行:

await pyodide.loadPackage('micropip')
await pyodide.runPythonAsync(`
    import micropip
    await micropip.install('textblob')
    from textblob import TextBlob
    // ... something
    
`)

但它仍然给出了上述错误。然后我尝试运行官方文档中的代码(https://pyodide.org/en/stable/usage/loading-packages.html

await pyodide.loadPackage("micropip");
        await pyodide.runPythonAsync(`
        import micropip
        micropip.install('snowballstemmer')
        import snowballstemmer
        stemmer = snowballstemmer.stemmer('english')
        print(stemmer.stemWords('go goes going gone'.split()))
      `);

但它仍然给了我同样的错误。有人可以指导我如何解决这个问题吗?我还尝试加载包('js')并将其导入到 runPythonAsync 中,但它仍然失败。

这是错误的完整版本:-

PythonError: Traceback (most recent call last):
  File "/lib/python3.9/asyncio/futures.py", line 201, in result
    raise self._exception
  File "/lib/python3.9/asyncio/tasks.py", line 258, in __step
    result = coro.throw(exc)
  File "/lib/python3.9/site-packages/micropip/_micropip.py", line 185, in install
    transaction = await self.gather_requirements(requirements, ctx, keep_going)
  File "/lib/python3.9/site-packages/micropip/_micropip.py", line 175, in gather_requirements
    await gather(*requirement_promises)
  File "/lib/python3.9/asyncio/futures.py", line 284, in __await__
    yield self  # This tells Task to wait for completion.
  File "/lib/python3.9/asyncio/tasks.py", line 328, in __wakeup
    future.result()
  File "/lib/python3.9/asyncio/futures.py", line 201, in result
    raise self._exception
  File "/lib/python3.9/asyncio/tasks.py", line 256, in __step
    result = coro.send(None)
  File "/lib/python3.9/site-packages/micropip/_micropip.py", line 284, in add_requirement
    metadata = await _get_pypi_json(req.name)
  File "/lib/python3.9/site-packages/micropip/_micropip.py", line 88, in _get_pypi_json
    return json.loads(await fetch_string(url))
  File "/lib/python3.9/site-packages/micropip/_micropip.py", line 60, in fetch_string
    return await (await pyfetch(url, **kwargs)).string()
  File "/lib/python3.9/site-packages/pyodide/http.py", line 229, in pyfetch
    from js import fetch as _jsfetch, Object
ImportError: cannot import name 'fetch' from 'js' (unknown location)

需要指导。

4

0 回答 0