2011-12-02 29 views
10

我已經安裝在我的Win7x64 Xampp和Python 2.7上。Windows上的Python&XAMPP:如何?

現在我試圖獲得Python語言的「力量」......我該怎麼做呢?

我已經試過了mod_python和mod_wsgi的,但第一個爲我的Python版本的不存在,當我嘗試安裝後,啓動Apache WSGI它給了我一個錯誤

< Directory "\x93C:/wsgi_app\x94"> path is invalid 

我加了一個<和'目錄'之間的空格,使字符串在這裏可見。

所以......任何人都知道是否有一個教程來安裝這些功能?

或者任何人都可以一步一步地向我解釋我該怎麼辦?

謝謝,抱歉,如果我不能如此解釋我。

如果你需要什麼,請問我。

+0

現在它給了我「錯誤500」或「錯誤403」:( – Bonny1992

回答

14

是的你是對的,mod_python不能用於Python 2.7。所以mod_wsgi是你的最佳選擇。

我會推薦AMPPS作爲python環境默認情況下啓用mod_python和python 2.5。 AMPPS Website

,如果你仍想繼續,

加入這一行在httpd.conf

LoadModule wsgi_module modules/mod_wsgi.so 

取消註釋httpd.conf中的行

Include conf/extra/httpd-vhosts.conf 

打開虛擬主機文件的httpd的虛擬主機.conf並添加

NameVirtualHost 127.0.0.1:80 
<VirtualHost 127.0.0.1:80> 
    <Directory "path/to/directory/in/which/wsgi_test.wsgi/is/present"> 
     Options FollowSymLinks Indexes 
     AllowOverride All 
     Order deny,allow 
     allow from All 
    </Directory> 
    ServerName 127.0.0.1 
    ServerAlias 127.0.0.1 
    WSGIScriptAlias /wsgi "path/to/wsgi_test.wsgi" 
    DocumentRoot "path/to/htdocs" 
    ErrorLog "path/to/log.err" 
    CustomLog "path/to/log.log" combined 
</VirtualHost> 

添加以下行wsgi_test.wsgi

def application(environ, start_response): 
    status = '200 OK' 
    output = 'Hello World!' 

    response_headers = [('Content-type', 'text/plain'), 
         ('Content-Length', str(len(output)))] 
    start_response(status, response_headers) 

    return [output] 

注意:不要在htdocs目錄測試目錄。因爲我還沒有嘗試過。這些步驟在AMPPS中適用於我。 :)

然後在您最喜歡的瀏覽器中訪問127.0.0.1/wsgi。你會看到Hello World !.

如果你沒有看到,請按照QuickConfigurationGuide

OR

您可以在httpd.conf里加上這些行

<IfModule wsgi_module> 
<Directory path/to/directory> 
    Options FollowSymLinks Indexes 
    AllowOverride All 
    Order deny,allow 
    allow from All 
</Directory> 
WSGIScriptAlias /wsgi path/to/wsgi_test.wsgi 
</IfModule> 
+1

虛擬主機是必需的? :)謝謝你的回覆:) :) – Bonny1992

+0

不,這是沒有必要的。您也可以將這些行添加到httpd.conf中。 <目錄路徑/到/目錄> 有FollowSymLinks指標 設置AllowOverride所有 訂單拒絕,允許 允許所有 WSGIScriptAlias/WSGI路徑/到/ wsgi_test.wsgi

+0

好與AMPPS作品現在:)但現在我可以從我的web服務器啓動python應用程序嗎? :) – Bonny1992

14

WSGI是好了很多,但至少我用Google搜索並試圖設置好幾天而沒有成功。 CGI效率較低,但由於大多數人只使用Windows進行開發,因此幾乎沒有區別。這非常容易設置!

CGI方法:

  1. 在XAMPP的\ apache的\的conf \ httpd.conf中尋找這一行:AddHandler的CGI腳本的CGI特等 的.asp。修改它,所以它看起來是這樣的:AddHandler的CGI腳本 的CGI特等的.asp的.py
  2. 在您創建的每個Python腳本的頂部,路徑設置爲你的Python版本。舉例來說,如果您的機器是在C:\ Python27寫:#!/ Python27 /蟒蛇在XAMPP \ cgi-bin目錄和訪問本地主機/
  3. 認沽測試樣品測試代碼的cgi-bin/your-file.py

樣品測試代碼(其他城市根據你安裝了它在那裏評論蟒蛇路徑):

#!C:/Python27/python 

print "Content-type: text/html\n\n" 
print "<html><head><title>Hello World from Python</title></head><body>Hello World from a Python CGI Script</body></html>" 

我在XAMPP 1.8.1測試這一點,如果事情不工作讀取tihs:

來源:http://elvenware.com/charlie/development/web/Python/Xampp.html

相關問題