Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 脚本不起作用的Shebang_Python_Django_Pythonanywhere - Fatal编程技术网

Python 脚本不起作用的Shebang

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

我正在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 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'>