3

I'm trying to load the package StanfordCoreNLP to get the correct parsing for the movie reviews presented in their page (https://nlp.stanford.edu/sentiment/treebank.html): (I'm using MAC)

nlp = StanfordCoreNLP("/Users//NLP_models/stanford-corenlp-full-2018-01-31")

But get the error:

Traceback (most recent call last):
  File "/Users/anaconda3/lib/python3.6/site-packages/psutil/_psosx.py", line 295, in wrapper
    return fun(self, *args, **kwargs)
  File "/Users/anaconda3/lib/python3.6/site-packages/psutil/_psosx.py", line 480, in connections
    rawlist = cext.proc_connections(self.pid, families, types)
PermissionError: [Errno 1] Operation not permitted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 2411, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1802, in run
    launch(file, globals, locals)  # execute the script
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc) 

...
...
...

File "/Users/anaconda3/lib/python3.6/site-packages/stanfordcorenlp/corenlp.py", line 79, in __init__
if port_candidate not in [conn.laddr[1] for conn in psutil.net_connections()]:

File "/Users/anaconda3/lib/python3.6/site-packages/psutil/__init__.py", line 2191, in net_connections
    return _psplatform.net_connections(kind)
  File "/Users/anaconda3/lib/python3.6/site-packages/psutil/_psosx.py", line 229, in net_connections
    cons = Process(pid).connections(kind)
  File "/Users/anaconda3/lib/python3.6/site-packages/psutil/_psosx.py", line 300, in wrapper
    raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=5488)

I tried

conda update conda
conda update anaconda-navigator
conda update navigator-updater

But it didn't help. Any ideas??

Thanks!!

Cranjis
  • 1,590
  • 8
  • 31
  • 64

3 Answers3

1

I have the same problem, and I got it work by running the code using sudo like below:

sudo /Users/edamame/workspace/git/chinese_nlp/venv/bin/python3 chinese_segmenter1.py

Hope this works for you as well.

Edamame
  • 23,718
  • 73
  • 186
  • 320
0

Same problem here.

A lot of discussion of this points to https://github.com/ContinuumIO/anaconda-issues/issues/1984, which suggests updating to the latest Navigator, and running as root (via sudo).

I've tried both and see no change at all (you may be more fortunate).

https://github.com/Lynten/stanford-corenlp/issues/26 references a tweaked version of corenlp.py that claims to avoid the problem, though I haven't gotten it to work either.

TextGeek
  • 1,196
  • 11
  • 23
0

This problem seems to be specific to Mac OS X which would not allow Python to check the current port.

Comment this portion of code of corenlp.py file:

        if self.port is None:
        for port_candidate in range(9000, 65535):
            if port_candidate not in [conn.laddr[1] for conn in psutil.net_connections()]:
                self.port = port_candidate
                break

        if self.port in [conn.laddr[1] for conn in psutil.net_connections()]:
            raise IOError('Port ' + str(self.port) + ' is already in use.')

Replace by this line:

        self.port = 9999

Source: https://github.com/Lynten/stanford-corenlp/issues/26#issuecomment-445507811

Another solution is to run StanfordCoreNLP with a sudo command line.

Claude COULOMBE
  • 3,434
  • 2
  • 36
  • 39
  • Please don't post [identical answers](https://stackoverflow.com/a/61832702/874188); instead, vote to close as duplicate. – tripleee Jul 28 '20 at 04:00