简体   繁体   English

将python可执行文件添加到HTML中,我需要做什么?

[英]What do I need to do for adding python executable to HTML?

我使用乌龟图形在python中制作了自己的游戏,我想将其转换为可在HTML中运行的可执行文件,我是否应该了解其他信息?

Edit: An executable is not likely what you're looking for per Chris' answer . 编辑:根据Chris的回答,可执行文件不太可能是您想要的。 He also provides info about making an installer, if you do want to accomplish that. 如果您确实想完成安装程序,他还将提供有关制作安装程序的信息。 My answer addresses getting your Python game running in the browser. 我的答案解决了让Python游戏在浏览器中运行的问题。

When I initially saw this question, I thought it wasn't a thing. 当我最初看到这个问题时,我认为这不是问题。 However, Python is just a language. 但是,Python只是一种语言。 Anything can interpret and run Python logic. 任何东西都可以解释和运行Python逻辑。 It's just a matter if someone has built something that works in the browser and interprets Python. 是否有人在浏览器中构建了可以解释Python的东西,这只是一个问题。

After some Google searching, I found Skulpt: http://www.skulpt.org/ . 在Google搜索之后,我找到了Skulpt: http : //www.skulpt.org/ It appears to be a Javascript implementation of a Python interpreter. 它似乎是Python解释器的Javascript实现。 This is important because browsers only understand Javascript, not Python. 这很重要,因为浏览器只能理解Javascript,而不能理解Python。

Something worth noting is that Skulpt appears to only have partial support for Python 3. It mostly focuses on Python 2. This could be a major concern because Python 2 is scheduled for end of life January 1st, 2020 (at least, that's what pip told me). 值得注意的是,Skulpt似乎仅部分支持Python3。这主要是针对Python2。这可能是一个主要问题,因为Python 2计划于2020年1月1日终止使用(至少,这是pip所说的)我)。

There are examples of using Skulpt on its page. 在其页面上有使用Skulpt的示例。 Heads up that you'll likely need to learn some amount of Javascript, but if you're comfortable with Python already, that shouldn't be terrible. 请注意,您可能需要学习一定数量的Javascript,但是如果您已经熟悉Python,那应该不会很糟糕。

Edit: There also appears to be Brython: https://brython.info/ . 编辑:似乎还有Brython: https ://brython.info/。 This is a Python 3-focused implementation. 这是一个以Python 3为重点的实现。 At first glance, it looks a little easier to use, too. 乍一看,它看起来也更易于使用。

Hope this helps! 希望这可以帮助!

Please know that executables (.exe) & browsers tend not to work together. 请注意,可执行文件(.exe)和浏览器往往无法协同工作。 See this stackoverflow question referring to .exe's & html The long & short of it is that you can setup .exe's so they can be downloaded, but not rendered in the browser. 请参阅有关.exe和htmlstackoverflow问题 。长/短之处在于您可以设置.exe以便可以下载它们,但不能在浏览器中呈现。

If you want to convert your script to a .exe file, you'll need something like pyinstaller . 如果要将脚本转换为.exe文件,则需要pyinstaller类的pyinstaller Here's a link to some info about installing & using it. 这是一些有关安装和使用它的信息的链接。

TheBeege's answer is on point with rendering in the browser with python when you already have code written with turtle . TheBeege的答案是当您已经用turtle编写代码时,在浏览器中使用python进行渲染。 I just wanted to make sure anyone coming here looking for info on python with executables could find it. 我只是想确保任何来这里寻找具有可执行文件的python信息的人都能找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM