双击运行Python文件 [英] Running Python file by double-click

查看:91
本文介绍了双击运行Python文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常烦人的问题,我无法仅通过双击来运行Python文件.

I have really annoying problem, I cannot run a Python file just by double-clicking.

我尝试将其设置为使用idle.bat打开文件,但只能双击启动IDLE编辑器,而不会运行Python文件.

I have tried to set it to open the file with idle.bat but that only starts IDLE editor on double-click, it does not run the Python file.

推荐答案

您安装了哪个版本的Python?

What version of Python do you have installed?

您应该编写自己的批处理文件以执行python二进制文件和脚本.

You should write your own batch file to execute your python binary and your script.

例如,在Windows上默认安装Python 2.7时,这可能是脚本的全部内容.

For example, with a default Python 2.7 installation on Windows, this could be the entire contents of your script.

myscript.bat:

ECHO ON
REM A batch script to execute a Python script
SET PATH=%PATH%;C:\Python27
python yourscript.py
PAUSE

将此文件另存为"myscript.bat"(确保它不是"myscript.bat.txt"),然后双击它.

Save this file as "myscript.bat" (make sure it's not "myscript.bat.txt"), then double click it.

这篇关于双击运行Python文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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