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實驗

相關文章
相關標籤/搜索