I am doing a project in Natural Language Processing using nltk
in python.
The block structure of project is as follows:
- Interface (in php) ->
- [NLP Engine] (in python) ->
- API calls (in php) ->
- Result (in php)
The input is supposed to go via GET method from PHP Interface to the Python Engine.
Background:
I have created a virtual host (url=/linguistics/
) server using Easy-PHP Dev Server (Location=D:\Computational_Linguistics
). I have enabled it so that it can execute Test.py
so that when I type linguistics/Test.py
, it executes.
Issue:
The basic CGI was successfully executed and I could see the output in Chrome. But as soon as I imported another module, it returned this error:
Server error!
The server encountered an internal error and was unable to complete your request.
Error message: End of script output before headers: engine.py
If you think this is a server error, please contact the webmaster.
Error 500
linguistics Apache/2.4.4 (Win32) PHP/5.5.0
When I do NOT import nltk (or any other non-standard package) it works.
I did do the websearch to find the solution, and came to know I have to setup some environment variables to make it work. But, I can not figure out how.
My code:
#!C:/Python27/python.exe
import nltk
from nltk import *
import re
import cgi, cgitb
inpt=cgi.FieldStorage()
str_in = inpt.getvalue('query')
def is_noun (str):
tags=nltk.pos_tag(nltk.word_tokenize(str))
for i in tags:
if i[1][1]=='N' or i[1][1]=='V': #Finding out the Nouns and the Verbs.
print "<h5>%s is a noun.<h5>" %i[0]
is_noun(str_in)
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Hello - Second CGI Program</title>"
print "</head>"
print "<body>"
is_noun(str_in)
print "</body>"
print "</html>"