Python编程:下载20个新闻组数据时,sklearn库访问被拒绝文件夹错误

时间:2017-11-30 00:04:34

标签: python scikit-learn

在尝试下载20个新闻组数据时,在Python中获取访问被拒绝错误 下面是方法调用和错误的堆栈跟踪。 sklearn是用于通过以下方法调用下载数据的库。

from sklearn.datasets import fetch_20newsgroups
groups=fetch_20newsgroups()

错误是拒绝访问以下文件。我改变了访问权限 写入对以下文件的访问权限,但它以编程方式更改回读取访问权限,并且不会下载数据。

  

PermissionError:[WinError 5]访问被拒绝:   'C:\用户\ nvishwar \ scikit_learn_data \ 20news_home \ 20news-bydate测试\ sci.crypt'

完整堆栈跟踪:

c:\ProgramData\Anaconda3>python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn.datasets import fetch_20newsgroups
>>> groups=fetch_20newsgroups()
Downloading 20news dataset. This may take a few minutes.
Downloading dataset from https://ndownloader.figshare.com/files/5975967 (14 MB)
Traceback (most recent call last):

  File "<stdin>", line 1, in <module>
  File "c:\ProgramData\Anaconda3\lib\site-packages\sklearn\datasets\twenty_newsgroups.py", line 215, in fetch_20newsgroups
    cache_path=cache_path)

  File "c:\ProgramData\Anaconda3\lib\site-packages\sklearn\datasets\twenty_newsgroups.py", line 86, in download_20newsgroups
    tarfile.open(archive_path, "r:gz").extractall(path=target_dir)
  File "c:\ProgramData\Anaconda3\lib\tarfile.py", line 2007, in extractall
    numeric_owner=numeric_owner)
  File "c:\ProgramData\Anaconda3\lib\tarfile.py", line 2049, in extract
    numeric_owner=numeric_owner)
  File "c:\ProgramData\Anaconda3\lib\tarfile.py", line 2121, in _extract_member
    self.makedir(tarinfo, targetpath)
  File "c:\ProgramData\Anaconda3\lib\tarfile.py", line 2150, in makedir
    os.mkdir(targetpath, 0o700)
Perm`enter code here`issionError: [WinError 5] Access is denied: 'C:\\Users\\nvishwar\\scikit_learn_data\\20news_home\\20news-bydate-test\\sci.crypt'

1 个答案:

答案 0 :(得分:0)

您的数据肯定会被下载,而不是被提取。这不是因为任何文件的权限,而是因为目录的权限阻止os.mkdir(targetpath, 0o700)创建文件夹targetpath。您可以尝试更改这些权限,或者如果可行,从scikit_learn_data开始删除整个目录树并再次尝试。如果仍然无效,您可以在下载后手动提取文件。