简体   繁体   English

python-如何通过网络而不是可执行文件运行简单脚本

[英]python - how to run simple script via web instead of a executable file

I am trying to have someone without Python installed use a simple program. 我试图让没有安装Python的人使用一个简单的程序。

Have compiled it using py2exe, it worked, but it requires too much additional files. 使用py2exe对其进行了编译它可以工作,但是需要太多其他文件。 Have tried PyInstaller, but getting some errors when generating the executable file. 尝试过PyInstaller,但是在生成可执行文件时出现一些错误。

Anyway, I was thinking that it would be better upload that program to somewhere in the web, so, anyone with the link could use it in a much easier and practical way. 无论如何,我一直认为最好将程序上传到网络中的某个位置,因此,知道链接的任何人都可以以更简单实用的方式使用它。

Does anyone know how I could accomplish that ? 有谁知道我该怎么做?

  1. If you want someone to download your file, use command: 如果要有人下载文件,请使用命令:

     python -m SimpleHTTPServer 

    on your file dir. 在您的文件目录上。 And the someone use url {YourIp}:8000 with browser to access download. 有人通过浏览器使用URL {YourIp}:8000来访问下载。

  2. If you want to execute something in python script, create a small web service use flask: 如果要在python脚本中执行某些操作,请使用flask创建一个小型Web服务:

     from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): # Do your python script here return 'Hello World!' if __name__ == '__main__': app.run() 

    And also, the someone can execute your script use {YourIp}:8000 with browser. 而且,有人可以通过浏览器使用{YourIp}:8000执行您的脚本。

Except for the code, all you need is a server and a browser to access. 除了代码外,您只需要一台服务器和一个浏览器即可访问。

根据它的简单程度,您可以向他们发送文件并使用在线解释器(例如http://repl.it/languages/Python3)运行

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

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