Python 模块导入错误“ImportError:没有名为 mrjob.job 的模块”

发布于 2024-10-02 10:45:45 字数 1064 浏览 0 评论 0原文

系统:Mac OSX 10.6.5,Python 2.6

我尝试运行下面的 python 脚本:

from mrjob.job import MRJob

 class MRWordCounter(MRJob):
  def mapper(self, key, line):
      for word in line.split():
          yield word, 1

  def reducer(self, word, occurrences):
      yield word, sum(occurrences)

if __name__ == '__main__':
    MRWordCounter.run()

出现以下错误:

:~ vskarich$ python mrjob_test.py < words
Traceback (most recent call last):
  File "mrjob_test.py", line 1, in <module>
   from mrjob.job import MRJob
  ImportError: No module named mrjob.job

我像这样使用了 easy_install:

sudo easy_install mrjob

此命令下载了所需的 .egg 文件和我的 site-packages 目录for python 看起来像这样:

:~ vskarich$ cd /Library/Python/2.6/site-packages

:site-packages vskarich$ ls

PyYAML-3.09-py2.6-macosx-10.6-universal.egg  
easy-install.pth
README       
mrjob-0.2.0-py2.6.egg
boto-2.0b3-py2.6.egg     
simplejson-2.1.2-py2.6-macosx-10.6-universal.egg

我不知道在这里做什么,因为我对 python 有点陌生;任何帮助将不胜感激。谢谢你!

System: Mac OSX 10.6.5, Python 2.6

I try to run the python script below:

from mrjob.job import MRJob

 class MRWordCounter(MRJob):
  def mapper(self, key, line):
      for word in line.split():
          yield word, 1

  def reducer(self, word, occurrences):
      yield word, sum(occurrences)

if __name__ == '__main__':
    MRWordCounter.run()

I get the following error:

:~ vskarich$ python mrjob_test.py < words
Traceback (most recent call last):
  File "mrjob_test.py", line 1, in <module>
   from mrjob.job import MRJob
  ImportError: No module named mrjob.job

I had used easy_install like so:

sudo easy_install mrjob

This command downloaded the needed .egg file, and my site-packages directory for python looks like this:

:~ vskarich$ cd /Library/Python/2.6/site-packages

:site-packages vskarich$ ls

PyYAML-3.09-py2.6-macosx-10.6-universal.egg  
easy-install.pth
README       
mrjob-0.2.0-py2.6.egg
boto-2.0b3-py2.6.egg     
simplejson-2.1.2-py2.6-macosx-10.6-universal.egg

I am not sure what to do here as I am somewhat new to python; any help would be much appreciated. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热情消退 2024-10-09 10:45:45

两个建议:

  1. 确保 site-packages 目录中已安装的 Egg 和文件没有任何文件或目录权限问题。

  2. 如果您安装了 Python 2.6 的另一个实例(除了 /usr/bin/python2.6 中 Apple 提供的实例),请确保您安装了单独版本的 easy_install为它。按原样,您的输出表明它几乎肯定是使用 Apple 提供的 easy_install 安装在 /usr/bin 中,该文件适用于 Apple 提供的 Python。最简单的方法是使用新的安装 Distribute 包Python。

Two suggestions:

  1. Make sure you don't have any file or directory permissions problems for the installed eggs and files in the site-packages directory.

  2. If you have installed another instance of Python 2.6 (besides the Apple-supplied one in /usr/bin/python2.6), make sure you have installed a separate version of easy_install for it. As is, your output indicates it was almost certainly installed using the Apple-supplied easy_install in /usr/bin which is for the Apple-supplied Python. The easiest way to do that is to install the Distribute package using the new Python.

信愁 2024-10-09 10:45:45

我遇到了同样的问题,我尝试了pip install mrjobsudo easy_install mrjob。看起来安装成功,但是当我运行一个简单的示例脚本时,出现导入错误。

我按照以下说明使其正常工作: http://pythonhosted.org// mrjob/guides/quickstart.html#installation

简而言之,我从 github 克隆了源代码并运行 python setup.py install。不过,我的问题可能与你的不同。运行 pip-install 和 easy_install 后,我的 site-packages 目录中没有 mrjob 的任何内容。

I had the same problem, I tried pip install mrjob, sudo easy_install mrjob. It looked like it installed successfully, but when I ran a simple example script, I got the import error.

I got it to work by following the instructions at: http://pythonhosted.org//mrjob/guides/quickstart.html#installation.

In a nutshell, I cloned the source code from github and ran python setup.py install. My problem might be different from yours, though. There was nothing in my site-packages directory for mrjob after running pip-install and easy_install.

情深已缘浅 2024-10-09 10:45:45

mrjob 包可以通过运行以下命令来安装:
pip install mrjob
安装后,错误就会解决。
它对我来说有效。

mrjob package can be installed by running following command:
pip install mrjob
After installation, the error will be solved.
It worked in my case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文