nltk下载错误13权限被拒绝mac

时间:2017-03-20 16:13:16

标签: nltk

我在mac OS X的终端上输入nltk.download()后运行了命令python3。然后我收到此错误

PermissionError: [Errno 13] Permission denied: '/Users/shreya/nltk_data/corpora/panlex_swadesh.zip'

这是我在终端上得到的:

>>> nltk.download()
showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/downloader.py", line 1867, in run
    for msg in self.data_server.incr_download(self.items):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/downloader.py", line 529, in incr_download
    for msg in self._download_list(info_or_id, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/downloader.py", line 572, in _download_list
    for msg in self.incr_download(item, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/downloader.py", line 543, in incr_download
    for msg in self.incr_download(info.children, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/downloader.py", line 529, in incr_download
    for msg in self._download_list(info_or_id, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/downloader.py", line 572, in _download_list
    for msg in self.incr_download(item, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/downloader.py", line 549, in incr_download
    for msg in self._download_package(info, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/downloader.py", line 600, in _download_package
    os.remove(filepath)
PermissionError: [Errno 13] Permission denied: '/Users/shreya/nltk_data/corpora/panlex_swadesh.zip'

2 个答案:

答案 0 :(得分:2)

您对此文件的权限有误。您需要使用sudo执行脚本,或者最好通过运行此命令来更改权限:

sudo chmod +rwx /Users/shreya/nltk_data/corpora/panlex_swadesh.zip

此外,如果要更改目录中的所有权限,可以运行:

sudo chmod -R +rwx /Users/shreya/nltk_data/

答案 1 :(得分:0)

出于某种原因,您的python下载过程无权将文件下载到nltk_data目录中。这很清楚。由于后者位于您的主目录下(假设您 用户shreya),因此无法确定可能出现的问题。您可以编辑您的答案以提供更多信息,包括您正在运行的OS X版本以及可能与您的环境相关的任何其他信息。

您也可以尝试不同的方法:

  1. 删除整个nltk_data文件夹,退出并重新启动Python,然后重试。
  2. 指示交互式下载程序将文件放在不同的目录中(请参阅底部的字段)。
  3. 启动IDLE(例如,在终端输入idleidle3)并在IDLE控制台中运行您的python代码。
  4. 也许其中一个会起作用。如果没有,您将 以提供更多信息。