【问题标题】:psutil.AccessDenied Error while trying to load StanfordCoreNLPpsutil.AccessDenied 尝试加载 StanfordCoreNLP 时出错
【发布时间】:2018-03-04 21:11:17
【问题描述】:

我正在尝试加载包 StanfordCoreNLP 以获得正确解析他们页面中显示的电影评论 (https://nlp.stanford.edu/sentiment/treebank.html):(我正在使用 MAC)

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

但得到错误:

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)

我试过了

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

但这并没有帮助。 有什么想法吗??

谢谢!!

【问题讨论】:

标签: python-3.x nlp connection stanford-nlp psutil


【解决方案1】:

我有同样的问题,我通过使用sudo 运行代码来解决它,如下所示:

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

希望这也适用于您。

【讨论】:

    【解决方案2】:

    同样的问题。

    很多讨论都指向https://github.com/ContinuumIO/anaconda-issues/issues/1984,它建议更新到最新的 Navigator,并以 root 身份运行(通过 sudo)。

    我都试过了,根本看不到任何变化(你可能更幸运)。

    https://github.com/Lynten/stanford-corenlp/issues/26 引用了一个经过调整的 corenlp.py 版本,声称可以避免这个问题,尽管我也没有让它工作。

    【讨论】:

      【解决方案3】:

      这个问题似乎是 Mac OS X 特有的,它不允许 Python 检查当前端口。

      注释corenlp.py文件这部分代码:

              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.')
      

      用这一行替换:

              self.port = 9999
      

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

      另一个解决方案是使用 sudo 命令行运行 StanfordCoreNLP。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-30
      • 2016-08-29
      • 1970-01-01
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      • 2018-03-05
      相关资源
      最近更新 更多