系统ubuntu
安装NLTK之前,先用一下apt-cache search命令搜索一下NLTK包在软件源中具体的名字:
$ apt-cache search nltk #搜索软件包
$ apt-cache depends python-nltk #了解具体依赖的包
具体步骤如下:
首先安装setuptools(http://pypi.python.org/pypi/setuptools),
如果你进入上面的链接,会发现按照里面的提示安装,是不能成功的。
下面,我把这步说一下:
首先:
1.wget -q http://peak.telecommunity.com/dist/ez_setup.py
2.python ez_setup.py ( 这一步必然失败,是为了第三步取得url准备的.)
运行这行的时候,linux会停留在Downling ~~~~~这类似的上面.
这是因为你的这个目录下中没有setuptools-0.6c8-py2.4.egg东西.
3. wget http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c8-py*.*.egg
改成相应的python版本即可,
你也可以直接下载setuptools-0.6c8-py*.*.egg,然后运行
sudo sh 文件路径
注意:第三步的url是根据第二步得到的url.
然后,安装pip。sudo easy_install pip
然后,安装Numpy sudo pip install -U numpy,这个可能出错,例如缺少python-dev等等,具体看自己的情况。
然后,就是PyYaml sudo pip install -U Pyyaml
然后,安装nltk
最后就是测试nltk:
在终端下输入import nltk,不报错就成功了。
这边是英文原文
- Install Setuptools: Download the corresponding version of Setuptools fromhttp://pypi.python.org/pypi/setuptools (scroll to the bottom, and pick the filename that contains the right version number and which has the extension .egg). Install it by typing sudo sh Downloads/setuptools-...egg, giving the location of the downloaded file.
- Install Pip: run sudo easy_install pip
- Install Numpy (optional): run sudopipinstall -Unumpy
- Install PyYAML and NLTK: run sudopipinstall -Upyyamlnltk(建议分两步)
- Test installation: run python then typeimportnltk