【发布时间】:2017-01-23 02:09:45
【问题描述】:
我正在阅读编程集体智慧书。在第 2 章中,我在执行此步骤时遇到问题
>>>from recommendations import critics
终端显示这条消息
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name critics
整个代码是
# A dictionary of movie critics and their ratings of a small
# set of movies
critics = {'Lisa Rose': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.5,
'Just My Luck': 3.0, 'Superman Returns': 3.5, 'You, Me and Dupree': 2.5,
'The Night Listener': 3.0},
'Gene Seymour': {'Lady in the Water': 3.0, 'Snakes on a Plane': 3.5,
'Just My Luck': 1.5, 'Superman Returns': 5.0, 'The Night Listener': 3.0,
'You, Me and Dupree': 3.5},
'Michael Phillips': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.0,
'Superman Returns': 3.5, 'The Night Listener': 4.0},
'Claudia Puig': {'Snakes on a Plane': 3.5, 'Just My Luck': 3.0,
'The Night Listener': 4.5, 'Superman Returns': 4.0,
'You, Me and Dupree': 2.5},
'Mick LaSalle': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,
'Just My Luck': 2.0, 'Superman Returns': 3.0, 'The Night Listener': 3.0,
'You, Me and Dupree': 2.0},
'Jack Matthews': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,
'The Night Listener': 3.0, 'Superman Returns': 5.0, 'You, Me and Dupree': 3.5},
'Toby': {'Snakes on a Plane':4.5,'You, Me and Dupree':1.0,'Superman Returns':4.0}}
【问题讨论】:
-
recommendations.py是否存储在您可以访问的位置?您是否将该文件所在的路径附加到sys.path?如果没有,那么 Python 没有在“正确”文件夹中查找recommendations.py。 -
将
recommendations.py复制到您开始pythonREPL的位置。 -
@not_a_robot 谢谢你的重播,我做了所有这些步骤,但终端仍然显示相同的消息。
标签: python