Pyscript导入pygame后加载时间太长

huangapple go评论54阅读模式
英文:

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:

&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;PyScript TEST&lt;/title&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://pyscript.net/alpha/pyscript.css&quot; /&gt;
    &lt;script defer src=&quot;https://pyscript.net/alpha/pyscript.js&quot;&gt;&lt;/script&gt; 
  &lt;/head&gt;

  &lt;py-env&gt;
    - pygame
&lt;/py-env&gt;

  &lt;body&gt;
    &lt;py-script src=&quot;Game.py&quot;&gt;

    &lt;/py-script&gt;
  &lt;/body&gt;
&lt;/html&gt;

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): 无法安装包 &#39;pygame&#39;。
原因:找不到包 &#39;pygame&#39; 的纯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) &#39;pygame&#39;. 
Reason: Can&#39;t find a pure Python 3 Wheel for package(s) &#39;pygame&#39;.
See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel for more information.

huangapple
  • 本文由 发表于 2023年6月1日 04:26:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76377037.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定