如何在没有 pyinstaller 的情况下使用“./”创建 python 可执行文件

How to create a python executable with "./" without pyinstaller

我需要将我的程序发送给将使用 makefile 编译它的人,并且没有 pyinstaller 或使用 pip3 安装任何东西。

它需要在 linux 上工作。

可能吗? (我只能找到有关pyinstaller和pyexe的答案)。

如果你想使用 ./file.py 命令制作一个 file.py 可执行文件,你首先必须在文件的第一行添加 shebang: #!/usr/bin/env python3 用于 python 3.x 或 #!/usr/bin/env python2 如果您仍在使用 python 2.7

下一步是更改文件的权限以使其可执行。

您可以通过在提示符

中输入 chmod 744 file.py 来完成
$ nano file.py
  GNU nano 2.0.6                             File: file.py                  

#!/usr/bin/env python3

name = input("Name: ")

print('Hello, {}'.format(name))
$ ./file.py
-bash: ./file.py: Permission denied
$ chmod 744 file.py
$ ./file.py
Name: Osa
Hello, Osa