真的辛酸。先說環境win10 x64, python2.7
下載下傳pyltp包
anaconda和pip都沒有依賴,需要自己手動下載下傳、配置。
下載下傳pyltp并解壓到任意位置
下載下傳頁面:https://github.com/hit-scir/pyltp
下載下傳ltp并解壓到任意位置
下載下傳頁面:https://github.com/hit-scir/ltp
将解壓後的ltp檔案夾命名為ltp,整體複制到pyltp中
也就是将ltp所有内容作為一個檔案夾放到pyltp中。解壓pyltp後所得到的檔案夾中已經有一個名為ltp的空檔案夾,把它覆寫即可。
安裝C擴充包
對于Python 2.7 來說,微軟直接推出了Microsoft Visual C++ Compiler for Python 2.7,下載下傳直接安裝即可。
http://www.microsoft.com/en-us/download/details.aspx?id=44266
這時候cmd進入pyltp包所在的位置,運作python setup.py install。
報錯:error: command 'cl.exe' failed: No such file or directory
解決方案:
SET VCPYTHONPATH=C:\Users\使用者名\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
在python27安裝目錄下的 Lib\distutils\msvs9compiler.py中第254行
if not productdir or not os.path.isdir(productdir):
toolskey = "VCPYTHONPATH"
toolsdir = os.environ.get(toolskey, None)
if toolsdir and os.path.isdir(toolsdir):
productdir = os.path.abspath(toolsdir)
if not os.path.isdir(productdir):
log.debug("%s is not a valid directory" % productdir)
return None
else:
log.debug("Env var %s is not set or invalid" % toolskey)
報錯:error: command 'C:\\Users\\使用者名\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2
直到一萬年以後,我才發現上面下載下傳的C++擴充程式根本不支援win10...它隻支援win7和win8。
是以現在的任務就是找到适合win10的py2.7的C++擴充。
解決方案:.net Framework 3.5 開啟C++選項。
部署模型檔案
完整的模型檔案下載下傳位址: http://pan.baidu.com/share/link?shareid=1988562907&uk=2738088569,我選擇的是目前最新的3.4.0版本(ltp-data-v3.4.0.zip)。
參考:
- https://www.cnblogs.com/zhang-pengcheng/p/4553672.html
- https://blog.csdn.net/laoyaotask/article/details/45312905
- https://blog.csdn.net/u010899985/article/details/79165325