using NLTK in a python script on a web server

1,462 views
Skip to first unread message

Ross

unread,
Feb 7, 2011, 8:33:54 PM2/7/11
to nltk-users
I want to run a python script which utilises the NLTK on my web server
to process user input which is submitted via a webpage form.

I have a working python script in the cgi-bin but when I add

import nltk

to the script I get the error

CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers

How can I solve this and get the modified script working?

thanks

Craig Hagerman

unread,
Feb 7, 2011, 8:45:22 PM2/7/11
to nltk-...@googlegroups.com
Is NLTK available on your server. I just went through this last week.
I have software I have created on my home computer and wanted to put
it on my server. It has Python, but no nltk. It took a few days of
back and forth communication for them to get it installed correctly.
What if you ssh into the server, start a Python session and then type
'import nltk'. Does that work or not?

Craig

> --
> You received this message because you are subscribed to the Google Groups "nltk-users" group.
> To post to this group, send email to nltk-...@googlegroups.com.
> To unsubscribe from this group, send email to nltk-users+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nltk-users?hl=en.
>
>

Eric Haskins

unread,
Feb 7, 2011, 10:53:52 PM2/7/11
to nltk-users
I setup mod_python on my Apache Servers here is a primer that may help
you

http://docs.python.org/howto/webservers.html

Eric Haskins

Philipp Nolte

unread,
Feb 8, 2011, 11:30:04 AM2/8/11
to nltk-users
Hi there,

Another question: How can I use pickled taggers on my webserver? Due
to high response time, I can't really load the pickle file every time
the script gets requested. I was thinking about letting another script
with the pickled file loaded running in the background and somehow
pass data to it. Is there some sort of best practice?

Philipp

JAGANADH G

unread,
Feb 8, 2011, 12:37:05 PM2/8/11
to nltk-...@googlegroups.com


On Tue, Feb 8, 2011 at 10:00 PM, Philipp Nolte <p...@daslaboratorium.de> wrote:
Hi there,

Another question: How can I use pickled taggers on my webserver? Due
to high response time, I can't really load the pickle file every time
the script gets requested. I was thinking about letting another script
with the pickled file loaded running in the background and somehow
pass data to it. Is there some sort of best practice?


If you are using pickled data etc in your program better use Django frame work

--
**********************************
JAGANADH G
http://jaganadhg.freeflux.net/blog
ILUGCBE
http://ilugcbe.techstud.org

Michael Geary

unread,
Feb 8, 2011, 12:43:32 PM2/8/11
to nltk-...@googlegroups.com
This is something I would like to do. What's the best way to store pickled data in the database? Do you use the pickle functions inside of NLTK, or the standard python one? Would you just store it as a binary blob in the database?

thanks,

michael


Jacob Perkins

unread,
Feb 8, 2011, 12:50:05 PM2/8/11
to nltk-users
For http://text-processing.com/ I use Django (fcgi behind nginx) and
nltk.data.load to load pickled objects. nltk.data.load caches each
object once it's loaded, so you don't have to worry about reloading.
But, the first time you load takes time, so it's a good idea to prime
the webserver by making requests to load the objects as soon as it
(re)starts. You may also have to worry about memory if you're using
(pre) forked processes, as each process will need its own copy of the
object.

Jacob
---
http://streamhacker.com/
http://twitter.com/japerk

Ross

unread,
Feb 8, 2011, 2:42:22 PM2/8/11
to nltk-users
Thanks everyone - I think I now see the problem - I'm pretty sure nltk
is not installed on the server. I will work with them to get it
installed.


all the best

Ross

unread,
Feb 23, 2011, 4:46:35 PM2/23/11
to nltk-users
Hi Craig

I am struggling to get any response from my web host regarding
installing nltk on the server. Can yu provide any hints on how you got
your code up and running? What do you mean by "ssh into the sever"?
I'm not sure how to do this?

thanks

On Feb 8, 12:45 pm, Craig Hagerman <cr...@hagerman.ca> wrote:
> Is NLTK available on your server. I just went through this last week.
> I have software I have created on my home computer and wanted to put
> it on my server. It has Python, but no nltk. It took a few days of
> back and forth communication for them to get it installed correctly.
> What if you ssh into the server, start a Python session and then type
> 'import nltk'. Does that work or not?
>
> Craig
>

Craig Hagerman

unread,
Feb 23, 2011, 6:29:08 PM2/23/11
to nltk-...@googlegroups.com
I opened a support ticket (help request) with my server provider and
asked nicely if they could install NLTK and MySQLdb. They looked into
it and then did so. I think this is a pretty standard kind of request
of web hosting companies.

ssh = secure shell. It is like bash or tsch etc but provides a way to
use the command line (securely) over an internet connection. Google
it. I think I might pay extra to have ssh access, but it allows me to
run / check scripts from the command line rather than just having an
unresponsive web page.

One alternative if your hosting company won't install nltk might be to
download nltk onto your home computer, decompress, and then upload it
to a directory viewable by a cgi-bin script. I think much (all? no
idea what percentage) of nltk is python rather than C code so this
should work. (crossed fingers) I tried this and was able to succefully
import nltk, but didn't make extensive use of this option since my
host did install the module for me after a couple days.

Craig

Ross

unread,
Feb 24, 2011, 3:58:02 PM2/24/11
to nltk-users
Thanks Craig

I have also asked my host to install nltk but they have no idea what
I'm talking about and after 3 weeks of me trying to explain nothings
happened! Which web hosting company are you using?

Craig Hagerman

unread,
Feb 24, 2011, 4:50:45 PM2/24/11
to nltk-...@googlegroups.com
I use justhost.com. Try opening another ticket and clearly asking if
it is possible to install a python module. Providing them with links
couldn't hurt either. My host uses debian so it was just an easy
'apt-get' install for them.

Good luck

Craig

Justin Olmanson

unread,
Feb 24, 2011, 5:03:57 PM2/24/11
to nltk-...@googlegroups.com
webfaction.com makes the process pretty easy if you end up moving to another host



Reply all
Reply to author
Forward
0 new messages