python自动打开软件_自动可执行的python文件,而无需从终端打开?

Sorry if this is on the wrong site ( maybe superuser ) but I'm trying to make my python.py file executable so I can click on it and it automatically does its thing, without me specifying it to open in the terminal by that default prompt, and I already have 'chmod +x' for its permissions.

Clarification:

I want to run it by clicking on it, not through the terminal ( I meant that when I said 'can click on it and it automatically does its thing ' )

Already have a shebang line

When I click it right now, it prompts me with do you want to open it in a text file, terminal - can I make it always default to opening in the terminal or is this just an oddball request?

解决方案

First, pick a file extension you want for files you want to have this behavior. pyw is probably a good choice.

Name your file that, and in your file browser associate that file type with python. In GNOME, you'd open its Properties window, go to the Open With tab, and enter python as a custom command.

Now here's the important part: That little dialog you've been getting asking you what you'd like to do with the file is because it is marked as executable. Remove the executable bit with chmod -x. Now when you double click it, it will simply be opened with the associated program.

Of course, if you want to run it from the command line, you'll now have to start it with python explicitly since it isn't marked executable. The shebang line doesn't matter anymore, but I'd leave it in anyway in case someone else marks it executable and expects it to work.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值