提问人:Pallav Purbia 提问时间:10/14/2023 最后编辑:YaroslavmPallav Purbia 更新时间:10/16/2023 访问量:42
无法使用 Pyscript 为我的 chrome 扩展导入 Python 库“Pytube”
Not Able to Import Python Library "Pytube" for my chrome extension using Pyscript
问:
我从这个存储库中获取了代码:[https://github.com/Arinze1020/pyscript-local-runtime/tree/master]
PythonError: Traceback (most recent call last): File
"/lib/python3.10/asyncio/futures.py", line 201, in result raise
self._exception File "/lib/python3.10/asyncio/tasks.py", line 232, in
__step result = coro.send(None) File "/lib/python3.10/site-
packages/_pyodide/_base.py", line 506, in eval_code_async await CodeRunner(
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 357, in
run_async coroutine = eval(self.code, globals, locals) File "", line 12, in
ModuleNotFoundError: No module named 'pytube'
弹出窗口 .html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Playlist length calculator</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<py-config>
[[runtimes]]
src = "runtime/pyodide.js"
name = "pyodide-0.21.3"
lang = "python"
</py-config>
<link rel="icon" type="icons/png" href="/icon-128.png" />
<link rel="stylesheet" href="popup.css" />
<link rel="stylesheet" href="runtime/pyscript.css" />
<script defer src="/setup.py"></script>
<script defer src="runtime/pyscript.js"></script>
</head>
<body>
<h2>Hello World!</h2>
<h4 id="datetime"></h4>
<!-- Python code below is intentionally left-aligned to utilise full width -->
<py-script src="pytube/__main__.py">
from js import document as popup # DOM for this popup page
from pytube import YouTube
link = input("Enter YouTube Playlist URL: ")
yt_playlist = Playlist(link)
</py-script>
<py-repl>
text = "This is a REPL session.<br>"
text += "You can add several lines of Python<br>"
text += "Then just press Shift-ENTER to run!"
print(text.upper())
</py-repl>
</body>
</html>
我尝试下载 Pytube 并添加扩展文件夹,但同样的错误不断出现。请用 Leymann 术语解释,因为我是 Web 开发的新手。互联网上没有关于如何在 pyscript 中为 chrome 扩展程序导入 python 库的信息
答:
0赞
Jeff Glass
10/16/2023
#1
要将 Python 包添加到您的页面以供 PyScript 使用,请将它们添加到标签中的键中。下面是一个示例:packages
<py-config>
<py-config>
packages = ['astropy', 'pyyaml', 'https://example.com/files/someWheel-py3-none-any.whl']
# packages can be from PyPI, Pyodide Packages, or Pyothon wheels
</py-config>
软件包可能无法在 PyScript/Pyodide 的上下文中使用,但这是安装可以使用的软件包的方法。
评论