从Python到.bat的转换 [英] Python to .bat conversion

查看:80
本文介绍了从Python到.bat的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Windows上的用户能够运行我的Python程序,因此我想将其转换为 .bat 文件.有没有办法转换它?我曾尝试搜索,但未找到任何内容.

I would like a user on Windows to be able to run my Python program, so I want to convert it to a .bat file. Is there a way to convert it? I've tried searching, but didn't find anything.

推荐答案

除非您的脚本很简单,否则无法将其翻译"为批处理文件.但是,存在两种选择:

Unless your script is trivial it will not be possible to 'translate' it into a batch file. However two options exist:

  • 创建一个批处理文件以运行python脚本
  • 尝试将脚本编译成可执行文件

第一个选项很简单.只需这样创建一个批处理文件:

The first option is trivial. Simply create a batch file as so:

@ECHO OFF
PATH_TO_PYTHON\python.exe PATH_TO_SCRIPT.py

如果您在公司环境中,则可以在网络上放置python安装并创建批处理文件以从那里运行脚本.否则,您将需要用户安装python.如果python在其路径上,则批处理文件可以简化为:

If you are in a corporate environment you could put a python installation on a network and create a batch file to run the script from there. Otherwise you will need the user to install python. If python is on their path then the batch file can be simplified to:

@ECHO OFF
python PATH_TO_SCRIPT.py

或者,有些选项可以尝试将脚本编译成.exe文件.我从未与他们取得任何成功,但 py2exe 似乎是最常见的.

Alternatively, there are options available that attempt to compile scripts into .exe files. I've never had any success with them, but py2exe seems the most common.

这篇关于从Python到.bat的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆