欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python2.7和NLTK安装详细教程

程序员文章站 2022-07-10 22:20:08
本文为大家分享了python2.7和nltk安装教程,具体内容如下 系统:windows 7 ultimate 64-bits python 2.7安装 下载pyth...

本文为大家分享了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,无错误表示成功。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。