下载NLTK数据时出现PermissionError [英] PermissionError when downloading NLTK data
问题描述
我使用Anaconda的Python 3.6.3发行版,它安装了NLTK,但没有安装NLTK DATA,我需要一个项目,问题是,当我尝试使用
I use Anaconda's Python 3.6.3 distribution and it comes with NLTK installed, but not with NLTK DATA, which I need for a project, the problem is, when I try to install with
nltk.download()
我知道
PermissionError: [Errno 13] Permission denied: '/usr/share/nltk_data'
因此,我进行了一些研究,发现有人建议将python运行为
So, I did some research, and I see people suggesting to run Python as
sudo python
但如果我这样做,它将启动基本Linux的Python,而不是Anaconda的Python.
but if I do that, it will launch the base Linux's Python, not Anaconda's.
tl;博士
我需要某种方式做类似的事情
I need some way to do something like
sudo conda python
如果您还有其他可行的建议,我也会接受.
If you have other suggestions that might work, I'll take it too.
谢谢!
推荐答案
查找可以向其写入文件的目录.例如.如果是/home/alvas/testdir
Find out which directory you can write files to. E.g. if it's /home/alvas/testdir
然后
>>> pip install -U nltk
>>> mkdir -p /home/alvas/testdir
>>> python -m nltk.download popular -d /home/alvas/testdir
如果您想知道如何为nltk_data
配置自定义路径,请在Python代码的开头:
If you want to know how to configure the custom path for nltk_data
, at the start of your Python code:
import nltk
nltk.data.path.append('/home/alvas/testdir')
这篇关于下载NLTK数据时出现PermissionError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!