mac配置python天然语言处理环境

 1、nltk安装

Ⅰ、工具安装步骤

一、根据python版本从 https://pypi.python.org/pypi/setuptools 下载对应版本的setuptools。而后,在终端下运行,sudo sh Downloads/setuptools-0.6c11-py2.7.eggpython

二、安装pip 在终端下运行sudo easy_install pipide

三、安装Numpy和matplotlib。运行 sudo pip install -U numpy matplotlib工具

四、安装pyyaml 和nltk 运行sudo pip install -U pyyaml nltkpost

Ⅱ、遇到的问题

一、安装pip常见问题

Error: No available formula with the name "pip"
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:

  https://pip.readthedocs.org/en/stable/installing/#install-pip

采用:spa

sudo easy_install pip

记得加sudocode

2.安装pyyaml常见问题:

sudo pip install -U pyyaml nltkorm

会遇到下面的问题:blog

Installing collected packages: six
Found existing installation: six 1.4.1
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.1:
...

采用下面的命令安装:ip

sudo pip install libName --upgrade --ignore-installed six

3.而后用上述一样的方式安装nltk资源

4.更新nmpy:

pip install --upgrade numpy
 import sklearn.datasets
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/sklearn/__init__.py", line 57, in <module>
    from .base import clone
  File "/Library/Python/2.7/site-packages/sklearn/base.py", line 11, in <module>
    from .utils.fixes import signature
  File "/Library/Python/2.7/site-packages/sklearn/utils/__init__.py", line 10, in <module>
    from .murmurhash import murmurhash3_32
  File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling

 参考文档: https://blog.wizchen.com/2016/06/17/Mac%E4%B8%8B%E6%9B%B4%E6%96%B0python%E7%A7%91%E5%AD%A6%E8%AE%A1%E7%AE%97%E5%BA%93numpy/ 

解决的办法是关闭sip:

重启电脑,在电脑启动时按住command+R,等画面上出现苹果图标,会看到打开了一个实用工具窗口,打开终端,输入:

csrutil disable

重启完毕后,再次在终端输入:sudo pip install -U numpy

就能够成功了,记得必定要加sudo。

五、同理,若是要安装matplotlib:sudo pip install matplotlib

也必定要加sudo

 2、nltk使用

一、进入到python

>>>import nltk

>>>nltk.download()

会调出一个对话框:能够进行package的下载

 

可是呢,通常是下载不成功的。须要手动去下载数据包

(能够联系本文做者要数据包,也能够本身百度一下,会有资源的),以后就能够进行文本的各类实验了。

二、自行python实验

相关文章
相关标签/搜索