Python 模块导入错误“ImportError:没有名为 mrjob.job 的模块”
系统: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
两个建议:
确保
site-packages
目录中已安装的 Egg 和文件没有任何文件或目录权限问题。如果您安装了 Python 2.6 的另一个实例(除了
/usr/bin/python2.6
中 Apple 提供的实例),请确保您安装了单独版本的easy_install为它。按原样,您的输出表明它几乎肯定是使用 Apple 提供的
easy_install
安装在/usr/bin
中,该文件适用于 Apple 提供的 Python。最简单的方法是使用新的安装 Distribute 包Python。Two suggestions:
Make sure you don't have any file or directory permissions problems for the installed eggs and files in the
site-packages
directory.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 ofeasy_install
for it. As is, your output indicates it was almost certainly installed using the Apple-suppliedeasy_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.我遇到了同样的问题,我尝试了
pip install mrjob
,sudo 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.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.