在Mac OS 10.9上为Python 3.4安装nltk

6 投票
1 回答
2878 浏览
提问于 2025-04-18 22:41

我一直在尝试在 Python 3.4 上运行 nltk,但一直没有成功。我按照这个网站的说明:http://www.nltk.org/install.html,用以下命令:

sudo pip install -U nltk

这个命令在 Mac 上预装的 2.7 版本上可以正常工作,但当我用

sudo pip3 install -U nltk

来尝试在 3.4 上安装时,却出现了以下错误:

    /usr/local/Cellar/python3/3.4.1_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'zip_safe'

  warnings.warn(msg)

/usr/local/Cellar/python3/3.4.1_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'test_suite'

  warnings.warn(msg)

/usr/local/Cellar/python3/3.4.1_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'entry_points'

  warnings.warn(msg)

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]

   or: setup.py --help [cmd1 cmd2 ...]

   or: setup.py --help-commands

   or: setup.py cmd --help



error: invalid command 'bdist_egg'

/private/tmp/pip_build_root/nltk/distribute-0.6.21-py3.4.egg

Traceback (most recent call last):

  File "/private/tmp/pip_build_root/nltk/distribute_setup.py", line 143, in use_setuptools

    raise ImportError

ImportError



During handling of the above exception, another exception occurred:



Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/private/tmp/pip_build_root/nltk/setup.py", line 23, in <module>

    distribute_setup.use_setuptools()

  File "/private/tmp/pip_build_root/nltk/distribute_setup.py", line 145, in use_setuptools

    return _do_download(version, download_base, to_dir, download_delay)

  File "/private/tmp/pip_build_root/nltk/distribute_setup.py", line 125, in _do_download

    _build_egg(egg, tarball, to_dir)

  File "/private/tmp/pip_build_root/nltk/distribute_setup.py", line 116, in _build_egg

    raise IOError('Could not build the egg.')

OSError: Could not build the egg.

Python 3.4 是通过 brew 安装的,并且 bumpy 和 setuptools 也都正确安装了。我在网上查了一些资料,发现有类似的问题,但没有找到明确的解决办法。

1 个回答

8

我刚从 PyPI 下载了 3.0.0b2 的 .tar.gz 文件,解压后在解压的目录里运行了

sudo python3 setup.py install

,一切都正常。我在用 pip3 安装的时候也遇到了同样的问题。我还想提一下,我是用 MacPorts 来管理 Python 和其他东西的,但希望这不会造成影响。

撰写回答