英文:
Pyscript taking forever to load after importing pygame
问题
I'm using PyScript for my website. Using Live Server, my website is taking forever to load after I try to install pygame. My PyScript code looks like this:
<!DOCTYPE html>
<html>
<head>
<title>PyScript TEST</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<py-env>
- pygame
</py-env>
<body>
<py-script src="Game.py">
</py-script>
</body>
</html>
However, and note that this only happens when I install pygame, it just says this for (at what seems to be the case at this rate) forever:
Loading runtime... Runtime created... Initializing components...
What can I do about this? It is very frustrating.
英文:
So, I'm using PyScript for my website. Using Live Server, my website is taking forever to load after I try to install pygame. My PyScript code looks like this:
<!DOCTYPE html>
<html>
<head>
<title>PyScript TEST</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<py-env>
- pygame
</py-env>
<body>
<py-script src="Game.py">
</py-script>
</body>
</html>
However, and note that this only happens when I install pygame, it just says this for (at what seems to be the case at this rate) forever:
Loading runtime... Runtime created... Initializing components...
What can I do about this? It is very frustrating.
答案1
得分: 1
如@SimonUnderwood所指出,PyGame目前不受Pyodide/PyScript支持。那些不仅仅是Python的库需要预先编译其C/Rust/Fortran等扩展以在Web Assembly中运行,并且可能需要其他调整。
尽管如此,未来解决类似问题的一个方法是使用更近期的PyScript版本。alpha
版本发布于2022年5月;在撰写本文时,最新版本是2023.03.1,于2023年3月发布,如该注释所示,而2023.05.1 Release Candidate 1刚刚发布。在这些更新的PyScript版本中,尝试加载无法使用的包将在页面顶部显示错误消息,如下所示:
(PY1001): 无法安装包 'pygame'。
原因:找不到包 'pygame' 的纯Python 3 Wheel。
参见:https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel 获取更多信息。
英文:
As @SimonUnderwood noted, PyGame isn't currently supported by Pyodide/PyScript. Libraries that aren't purely Python need to have their C/Rust/Fortran/etc extensions pre-compiled to run in Web Assembly, and other adjustments may be required as well.
That said, one thing that will help with issues like this in the future is to use a more recent version of PyScript. The alpha
release dates to May 2022; the most recent release at time of writing is 2023.03.1, released March 2023 as the notation implies, and 2023.05.1 Release Candidate 1 just went public. In these more-recent versions of PyScript, trying to load a non-viable package will present an error message at the top of the page like:
(PY1001): Unable to install package(s) 'pygame'.
Reason: Can't find a pure Python 3 Wheel for package(s) 'pygame'.
See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel for more information.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论