【问题标题】:Shebang for scripts not workingShebang 的脚本不起作用
【发布时间】:2015-11-07 13:31:01
【问题描述】:

我在 django 生产环境中使用 PythonAnyhwere。我有一个应该按计划运行的脚本。

因为我在 virtualenv 中安装了 django,所以脚本开始像

#!/usr/bin/env python
activate_this = '/home/myname/.virtualenvs/myenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

我得到的错误是

/usr/bin/env python: no such Python interpreter

没问题。所以我把它改成

#!/usr/bin/env python2.7

然后我得到了

/usr/bin/env python2.7: no such Python interpreter

/usr/bin/env python3.4: no such Python interpreter

我说好的,如果我根本没有 shebang 线怎么办? 日志错误:

line 1: activate_this: command not found
line 2: syntax error near unexpected token `activate_this,'
line 2: `execfile(activate_this, dict(__file__=activate_this))'

那怎么办呢?

【问题讨论】:

  • 你试过$which python并把输出放到你的shebang吗?
  • 没有。如何在我的脚本中实现它?
  • 如果您可以访问它,只需在终端中执行它。没有$ 符号
  • 外壳说/usr/bin/python
  • 尝试放到shebang中看看有没有帮助

标签: python django pythonanywhere


【解决方案1】:

你可以通过键入来知道你的 Python 解释器在哪里

$ which python

你也可以尝试这样的事情(或者可能没有env):

$ env python
Python 3.5.0 (default, Sep 20 2015, 11:28:25) 
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path
<module 'posixpath' from '/usr/lib/python3.5/posixpath.py'>

然后将lib更改为bin并省略/posixpath.py部分

【讨论】:

    猜你喜欢
    • 2011-03-08
    • 2019-03-28
    • 2015-03-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多