Cannot pass an argument to python with quot;#!/usr/bin/env pythonquot;(无法使用“#!/usr/bin/env python将参数传递给 python)
问题描述
我需要有一个直接可执行的 python 脚本,所以我用 #!/usr/bin/env python 启动了这个文件.但是,我还需要无缓冲的输出,所以我尝试了 #!/usr/bin/env python -u,但是失败了 python -u: no such file or directory.
I needed to have a directly executable python script, so i started the file with #!/usr/bin/env python. However, I also need unbuffered output, so i tried #!/usr/bin/env python -u, but that fails with python -u: no such file or directory.
我发现 #/usr/bin/python -u 有效,但我需要它来获取 PATH 中的 python 到支持虚拟 env 环境.
I found out that #/usr/bin/python -u works, but I need it to get the python in PATH to support virtual env environments.
我有什么选择?
推荐答案
最好使用环境变量来启用它.请参阅 python 文档:http://docs.python.org/2/using/cmdline.html
It is better to use environment variable to enable this. See python doc : http://docs.python.org/2/using/cmdline.html
你的情况:
export PYTHONUNBUFFERED=1
script.py
这篇关于无法使用“#!/usr/bin/env python"将参数传递给 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法使用“#!/usr/bin/env python"将参数传递给 python
基础教程推荐
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
