python - 如何在没有 pyinstaller 的情况下使用“./”创建 python 可执行文件
问题描述
我需要将我的程序发送给将使用 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
推荐阅读
- ios - 如何使用 MVC 范例 SWIFT 设置 UITableView
- c# - 转换日期时间?串起来
- heroku - 在免费计划中使用 Heroku
- java - Is there any component available in Camel to run standalone route?
- php - 在PHP中按列查找元素的总和
- java - 获取 PKIX 路径构建失败:jdk 更新后的 sun.security.provider.certpath.SunCertPathBuilderException
- c++ - 尝试使用 LogEntry C++ 为我的 String ADT 创建 Parse 函数
- sql-server - 将记录展平为值不为空的单行
- tensorflow - 物体检测,faster-rcnn
- azure - Azure AppInsights - Http 结果代码错误