请帮助新手在Mac OS 10.5.8上安装NLTK [英] Please help a newbie install NLTK on Mac OS 10.5.8

查看:98
本文介绍了请帮助新手在Mac OS 10.5.8上安装NLTK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程的新手.我一直在尝试各种方法在Mac(运行OS 10.5.8)上安装NLTK,但没有一种起作用.请帮忙!这是我到目前为止所做的.

I'm completely new to programming. I've been trying various ways to install NLTK on my Mac (running OS 10.5.8), and none of them is working. Please help! Here's what I've done so far.

由于起初我没有意识到更新版本的Python需要OS 10.6或更高版本,所以我首先尝试安装最新版本的Python 3和Python 2,但这显然行不通.然后我仔细检查,发现安装较旧(文件名为python-2.7.6-macosx10.3.dmg),安装成功.

Since at first I didn't realize that newer versions of Python required OS 10.6 or higher, I first tried to install the latest versions of both Python 3 and Python 2, but this obviously didn't work. I then cottoned on and found an older installation (the filename is python-2.7.6-macosx10.3.dmg), which installed successfully.

然后,我尝试按照此页面上的说明进行操作,我在下面复制了该内容:

I then tried to follow the instructions on this page, which I copy below:

  1. 安装Setuptools: http://pypi.python.org/pypi/setuptools

安装Pip:运行sudo easy_install pip

Install Pip: run sudo easy_install pip

安装Numpy(可选):运行sudo pip install -U numpy

Install Numpy (optional): run sudo pip install -U numpy

安装PyYAML和NLTK:运行sudo pip install -U pyyaml nltk

Install PyYAML and NLTK: run sudo pip install -U pyyaml nltk

测试安装:运行python,然后输入import nltk

Test installation: run python then type import nltk

第1步和第2步工作正常,但是当我尝试第3步和第4步时,出现错误.无论我尝试第3步还是第4步,该错误都是相同的:

Steps 1 and 2 worked fine, but when I try steps 3 and 4, I get an error. The error is the same whether I try step 3 or step 4:

unknown0021E9E0E476:~ Tom$ sudo pip install -U numpy
Traceback (most recent call last):
File "/usr/local/bin/pip", line 8, in <module> load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 271, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 2173, in load_entry_point
return ep.load()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/pkg_resources.py", line 1906, in loadentry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/Library/Python/2.5/site-packages/pip-1.4.1-py2.5.egg/pip/__init__.py", line 10, in <module>
from pip.util import get_installed_distributions, get_prog
File "/Library/Python/2.5/site-packages/pip-1.4.1-py2.5.egg/pip/util.py", line 17, in <module>
from pip.vendor.distlib import version
File "/Library/Python/2.5/site-packages/pip-1.4.1-py2.5.egg/pip/vendor/distlib/version.py", line 13, in <module>
from .compat import string_types
File "/Library/Python/2.5/site-packages/pip-1.4.1-py2.5.egg/pip/vendor/distlib/compat.py", line 276
return b''
         ^
SyntaxError: invalid syntax

然后我在此页面上找到了另一套说明.首先,您安装了我安装的Xcode和MacPorts(再次找到与10.5.8兼容的旧版本).我成功完成了以下几个步骤:安装了python27,将其设置为系统默认值(sudo端口选择--set python python27),并安装了依赖项py27-numpy,py27-yaml和py27-scipy.但是,我无法安装一个需要的软件包py27-matplotlib.当我尝试时会发生以下情况:

I then found a different set of instructions on this page. It first has you install Xcode and MacPorts, which I did (again finding older versions compatible with 10.5.8). I got through the next few steps successfully: installed python27, made it the system default (sudo port select --set python python27), and installed the dependencies py27-numpy, py27-yaml, and py27-scipy. However, I can't install one needed package, py27-matplotlib. Here's what happens when I try:

unknown0021E9E0E476:~ Tom$ sudo port install py27-matplotlib
--->  Computing dependencies for py27-matplotlib
--->  Dependencies to be installed: py27-pyobjc-cocoa py27-pyobjc py27-six py27-tkinter tk Xft2 tcl xorg-libXScrnSaver xorg-scrnsaverproto py27-tornado py27-backports-ssl_match_hostname py27-backports
--->  Staging py27-pyobjc into destroot
Error: org.macports.destroot for port py27-pyobjc returned: command execution failed
Error: Failed to install py27-pyobjc
Please see the log file for port py27-pyobjc for details:
/opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_python_py-pyobjc/py27-pyobjc/main.log
Error: The following dependencies were not installed: py27-pyobjc-cocoa py27-pyobjc py27-six py27-tkinter tk Xft2 tcl xorg-libXScrnSaver xorg-scrnsaverproto py27-tornado py27-backports-ssl_match_hostname py27-backports
To report a bug, follow the instructions in the guide:
http://guide.macports.org/#project.tickets
Error: Processing of port py27-matplotlib failed

没有此软件包,我将无法继续安装NLTK.

Without this package, I can't go on to install NLTK.

我也尝试过在PyCharm中安装NLTK,但这也不起作用:请参阅这个问题.我在这里尽我所能,所以任何帮助将不胜感激!

I've also tried installing NLTK in PyCharm, but that didn't work either: see this question. I'm at my wits' end here, so any help would be much appreciated!

ETA:问题已解决!我从 https://pypi.python.org/pypi/nltk并按照软件包中的安装说明进行操作,现在我可以在Python Shell中导入NLTK.是否有可能我只是在错误的目录中尝试安装东西? (我仍然想在PyCharm中使用NLTK,因此仍然欢迎您回答该问题.)

ETA: Problem solved! I downloaded the tar.gz file from https://pypi.python.org/pypi/nltk and followed the install instructions in the package, and now I can import NLTK in the Python shell. Is it possible that I was simply trying to install things while in the wrong directory? (I'd still like to use NLTK in PyCharm, so answers to that question will still be welcome.)

推荐答案

尝试安装包含matplotlib和numpy的scipy软件包,我是一门课程的助教,在该课程中我们大量使用numpy和matplotlib并使用scipy软件包安装是很多人的解决方案. 各个二进制和源程序包可从以下网站获得: scipy文档

Try installing the scipy package which includes matplotlib and numpy, I was a TA on a course where we used numpy and matplotlib quite a lot and using the scipy package to install was a solution for a lot of people. The individual binary and source packages are available from: scipy docs

  sudo port install py27-numpy py27-scipy py27-matplotlib py27-ipython +notebook py27-pandas py27-sympy py27-nose

这篇关于请帮助新手在Mac OS 10.5.8上安装NLTK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆