Python 脚本不起作用的Shebang
我正在django生产环境中使用pythonanywhere。我有一个脚本,应该按计划运行 因为我在virtualenv中安装了django,所以脚本的开头如下Python 脚本不起作用的Shebang,python,django,pythonanywhere,Python,Django,Pythonanywhere,我正在django生产环境中使用pythonanywhere。我有一个脚本,应该按计划运行 因为我在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
#!/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
或
我说,好吧,如果我没有一条蛇帮路线怎么办?
日志中的错误:
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
您也可以尝试类似的方法(或者不使用env
):
$env python
Python 3.5.0(默认,2015年9月20日11:28:25)
linux上的[GCC 5.2.0]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>导入操作系统
>>>操作系统路径
然后将
lib
更改为bin
并省略/posixpath.py
part您是否尝试了$which python
并将输出放在shebang中?否。我如何在脚本中实现它?如果您有权访问它,请在终端中执行它。如果没有$
签名,shell会说/usr/bin/python
试着把它放在shebang中,看看是否有帮助
$ which python
$ 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'>