Creating .exe file in Python

Laura Creighton lac at openend.se
Mon Jun 15 10:44:43 EDT 2015


In a message of Mon, 15 Jun 2015 06:42:48 -0700, subhabrata.banerji at gmail.com w

>I wrote a script as NLQ3. py 
>
>the code is written as, 
>
>import nltk
>import itertools 
>def nlq3(n):
>    inp=raw_input("Print Your Query:")
>    tag=nltk.pos_tag(nltk.wordpunct_tokenize(inp))
>    print "The Tagged Value Is:",tag
>    noun=[word[0] for word in tag if 'NN' in word[1]]
>    #print noun
>    #COMBINATION OF ALL ELEMENTS
>    for i in xrange(1,len(noun)+1):
>        comb= list(itertools.combinations(noun,i))
>        for i,v in enumerate(comb):
>            #print v
>            v1=list(v)
>            print v1
>
>I tried to call it as,
>C:\Tutorial>python hello.py
>...
>as 
>
>C:\Python27>python NLQ3.py
>
>C:\Python27>
>
>But I am not getting any output.

You need to fix your script first, and package it later.
That you are not getting any output indicates that you have
a severe problem.  And you do.  There is no main function in
the code that you posted.  So I made 2 small changes.

First, you aren't using n in your nlq3.  So I changed the function
definition to it to.

def nlq3():

Then I added these lines to the very bottom of the file.

if __name__ == "__main__":
    nlq3()

My file is named nlq3.py and now python nlq3.py gives output.  This
is an improvement.  But the code is still wrong.

It gets to here:

 tag=nltk.pos_tag(nltk.wordpunct_tokenize(inp))

and nltk is very unhappy about this.


lac at smartwheels:~/python$ python nlq3.py
Print Your Query:hello
Traceback (most recent call last):
  File "nlq3.py", line 18, in <module>
    nlq3()
  File "nlq3.py", line 5, in nlq3
    tag=nltk.pos_tag(nltk.wordpunct_tokenize(inp))
  File "/usr/local/lib/python2.7/dist-packages/nltk/tag/__init__.py", line 103, in pos_tag
    tagger = load(_POS_TAGGER)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 781, in load
    opened_resource = _open(resource_url)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 895, in _open
    return find(path_, path + ['']).open()
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 624, in find
    raise LookupError(resource_not_found)
LookupError: 
**********************************************************************
  Resource u'taggers/maxent_treebank_pos_tagger/english.pickle'
  not found.  Please use the NLTK Downloader to obtain the
  resource:  >>> nltk.download()
  Searched in:
    - '/home/lac/nltk_data'
    - '/usr/share/nltk_data'
    - '/usr/local/share/nltk_data'
    - '/usr/lib/nltk_data'
    - '/usr/local/lib/nltk_data'
    - u''
**********************************************************************

I don't know enough about nltk to know how to fix this.  You will have
to read nltk docs for that.  But get the code to work, first and
package it later, ok?

Laura



More information about the Python-list mailing list