簡體   English   中英

mod_python忽略shebang並使用Python 2而不是3

[英]mod_python ignoring shebang and using Python 2 instead of 3

我正在嘗試在瀏覽器中運行腳本。 我安裝了mod_python以便在服務器上運行基於Web的應用程序,並在腳本中設置了一個shebang:

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import sys

def index():
    print ("Content-type: text/html\n")
    print('Version Python {0}'.format(sys.version_info[0]))

if __name__ == '__main__':
    index()

但是,當我從瀏覽器( 應用程序 )運行腳本時,我看到Python版本是2。當從控制台運行腳本時,使用:

python3 index.py

預期使用Python版本3.3.5。 為什么mod_python忽略了shebang?

UPD。 問題結案

  • 我選擇退出mod_python。
  • 我在shebang中犯了一個錯誤(我應該為Unix設置\\ n行尾)。
  • 在PHP上編寫用於運行python 3的包裝器

在文件上設置可執行標志:

chmod a+x yourfile.py

然后,將其執行為:

./yourfile.py

使用shebang時,請按照以下步驟運行代碼。

這使您的文件可執行

chmod +x index.py

這有助於您的代碼執行

./index.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM