本文為大家分享了python2.7和NLTK安裝教程,具體內容如下
系統:Windows 7 Ultimate 64-bits
Python 2.7安裝
下載Python 2.7:官網下載地址
安裝
NLTK安裝
1、下載NLTK,下載地址, 安裝。
2、安裝時會出現以下錯誤:Python version 2.7 required, which was not found in the registry。
解決辦法:
(1)新建一個register.py文件,把以下代碼粘貼進去,保存到D盤。
# script to register Python 2.0 or later for use with win32all # and other extensions that require Python registry settings # # written by Joakim Loew for Secret Labs AB / PythonWare # # source: # http://www.pythonware.com/products/works/articles/regpy20.htm # # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html import sys from _winreg import * # tweak as necessary version = sys.version[:3] installpath = sys.prefix regpath = "SOFTWARE//Python//Pythoncore//%s//" % (version) installkey = "InstallPath" pythonkey = "PythonPath" pythonpath = "%s;%s//Lib//;%s//DLLs//" % ( installpath, installpath, installpath ) def RegisterPy(): try: reg = OpenKey(HKEY_CURRENT_USER, regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER, regpath) SetValue(reg, installkey, REG_SZ, installpath) SetValue(reg, pythonkey, REG_SZ, pythonpath) CloseKey(reg) except: print "*** Unable to register!" return print "--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) == pythonpath): CloseKey(reg) print "=== Python", version, "is already registered!" return CloseKey(reg) print "*** Unable to register!" print "*** You probably have another Python installation!" if __name__ == "__main__": RegisterPy()
(2)開始-運行-cmd,把D:/register.py復制進去按回車,出現Python 2.7 is already registered!則表示配置成功。
3、繼續安裝setuptools
4、安裝Pip:開始-運行-D:/Program Files/Python/Scripts/easy_install pip
5、安裝PyYAML和NLTK:開始-運行-D:/Program Files/Python/Scripts/pip install pyyaml nltk
6、測試安裝:開始-所有程序-Python 2.7-IDLE(Python GUI),輸入import nltk,無錯誤表示成功。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林站長站。
新聞熱點
疑難解答