Skip to main content
 首页 » 编程设计

python之使用 nohup 时更改 python 版本

2024年10月17日9daizhj

我正在尝试使用 linux nohup 命令运行一个名为 compare.py 的 python 程序,该命令使程序一直运行直到完成而不会中断。我的 python 程序包含只能在 python 2.7 上运行的包,当我使用 nohup 命令时,程序在 python 2.6 上运行。使用 nohup 时如何更改 python 版本?

例子:nohup python compare.py $

我试过这样做: 别名 python=python2.7

在启动程序之前,python 的版本没有切换。如何在运行 nohup 时将 python 版本切换到 2.7?

请您参考如下方法:

最简单的方法是使用 shebang 行来指定解释器。在你的 Python 文件的开头,放一些像

#!/usr/bin/python2.7 
# This should be a path to an interpreter that you know for sure is Python 2.7 

然后,使用 chmod +x file.py 使 Python 文件本身可执行,并省略 nohup 命令的 python 部分,例如。 nohup./compare.py.