我正在尝试使我的 python 脚本可执行而无需通过终端键入
蟒蛇测试.py
我想让它在我单击文件时能够运行。
我将如何在我的 Fedora 机器上执行此操作。
添加#!/bin/python为文件的第一行。或者,如果您不知道您的 python 可执行文件在哪里,请输入which python终端;然后复制结果并将其放在#!.
更改文件的权限,使其可执行chmod u+x test.py
我尝试了,但它仍然以 gedit 的形式打开
python要添加的命令。#!/usr/bin/env python。chmod u+x filename.py.py为.sh,这样您的 linux 发行版的 UI 就会将其识别为 shell 脚本并尝试执行。这是鹦鹉螺的错。打开 Nautilus(文件管理器),转到菜单 > 首选项。选择“行为”部分。在标题为“可执行文本文件”的字段中,选择“打开时执行可执行文本文件”选项。
添加#!/usr/bin/python为文件的第一行并将权限设置为 executable chmod 755 yourfile。
如果您没有任何特定的版本要求,那么使用第一行 as#!/usr/bin/env python将更有效并授予执行权限chmod u+x test.py
I know it can be too late, but i did have the same idea. (run python scripts in fedora) and found some trouble. My suggestion to you is to make a launcher with a .sh file, like this:
#!/bin/sh
gnome-terminal -x python yourscript.py
Give the permition to execute with chmod +x file.sh, them click and will run.
[^_~]
我使用 raspibian 操作系统(Linux)