为什么我会收到这个 AttributeError ?(python3,pygame) [英] Why am I getting this AttributeError ? (python3 , pygame)

查看:60
本文介绍了为什么我会收到这个 AttributeError ?(python3,pygame)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我收到的错误和我编写的代码.我知道有人问过类似的问题,但他们给出的解决方案与本案无关.而且我似乎无法弄清楚为什么我会收到此属性错误.我正在运行 python 3.3 和 pygame.我的操作系统是 ubuntu 12.10.我希望有人能找到这个问题的解决方案,这样我就可以继续进行这个物理模拟.

Below is the error I am receiving and the code I have written. I know similar questions have been asked , but the solutions they are given do not relate to this case. And I can't seem to figure out why I am receiving this attribute error. I am running python 3.3 and pygame. The OS im on is ubuntu 12.10. I hope someone can find a solution to this problem so I can continue working on this physics simulation.

Traceback (most recent call last):
  File "/media/lawton/D4B1-5B96/programming/Python/gamephysics.py", line 9, in <module>
    screen = pygame.display.set_mode((width, height))
AttributeError: 'module' object has no attribute 'display'

import pygame


background_colour = (255,255,255)

(width, height) = (300, 200)

screen = pygame.display.set_mode((width, height))

pygame.display.set_caption('Tutorial 1')

screen.fill(background_colour)

pygame.display.flip()

running = True
while running:
  for event in pygame.event.get():
    if event.type == pygame.QUIT():
      running = False

推荐答案

您正在使用另一个 pygame.py 文件遮蔽pygame 库,可能与 gamephysics.py 位于同一位置.

You are shadowing the pygame library with another pygame.py file, probably in the same location as gamephysics.py.

打印出违规模块的文件路径:

Print out the file path of the offending module:

import pygame

print('Path to pygame module:', pygame.__file__)

这将显示rogue"模块的位置.找到后,将其重命名为其他名称.

This will you show you where the 'rogue' module is located. Once you find it, rename it to something else.

这篇关于为什么我会收到这个 AttributeError ?(python3,pygame)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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