Pygame not importing correctly - python

I'm new to Python, and I'm trying to get started with Pygame.
When I run this code:
import pygame
pygame.init()
I get this error:
Traceback (most recent call last):
File "C:\Users\Jason\PycharmProjects\Game\myapp.py", line 6, in <module>
pygame.init()
AttributeError: 'module' object has no attribute 'init'
But when I try to see if I accidentally imported another file:
import pygame
import inspect
# Initialize the game engine
print(inspect.getfile(pygame))
pygame.init()
I get this weird error:
Traceback (most recent call last):
File "C:\Users\Jason\PycharmProjects\Game\myapp.py", line 5, in <module>
print(inspect.getfile(pygame))
File "C:\Python34\lib\inspect.py", line 518, in getfile
raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'pygame' (namespace)> is a built-in module
How can I import the right Pygame?
I'm using 3.4 on Windows 7 and Pygame 1.9.2a0 (for 3.2) in C:/Python34.
Thank you

It all has to with the version. That simple.
The original answer was here: https://stackoverflow.com/a/23484831/2486953
I had to download the 64 bit version from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Thanks #BrenBarn for your help!

Related

(AttributeError) installation problem with keyboard

I am having a issue when I try to use the keyboard module.
My code is:
import keyboard
keyboard.write('Hello.', 0.3)
And the error was:
C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe "C:/Users/user/Desktop/simple brain/keyboard.py"
Traceback (most recent call last):
File "C:\Users\user\Desktop\simple brain\keyboard.py", line 1, in <module>
import keyboard
File "C:\Users\user\Desktop\simple brain\keyboard.py", line 2, in <module>
keyboard.write('Hello.', 0.3)
AttributeError: partially initialized module 'keyboard' has no attribute 'write' (most likely due to a circular import)
Process finished with exit code 1
I used pip install keyboard in pycharm terminal.
How do I fix the installation of or properly install keyboard?
The name of your file is "keyboard.py". When you do import keyboard, python is trying to import your current file which is causing a circular import. Rename your file to something else.

Copied this code from the official arcade site but i get this error: AttributeError: module 'arcade' has no attribute 'Scene'

When I run my code I get
Traceback (most recent call last):
File "c:\Users\Luke Coopman\Python\game2.py", line 226, in <module>
main()
File "c:\Users\Luke Coopman\Python\game2.py", line 221, in main
window.setup()
File "c:\Users\Luke Coopman\Python\game2.py", line 66, in setup
self.scene = arcade.Scene()
AttributeError: module 'arcade' has no attribute 'Scene'
I copied the code from here: https://arcade.academy/examples/platform_tutorial/step_08.html
Most likely you're using Arcade 2.5.7 or older. Scene class was introduced on version 2.6.0. So you need to update your Arcade lib to the latest version.

AttributeError: module 'pyautogui' has no attribute 'size' [duplicate]

This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 2 years ago.
As a beginner in Python, I really don't know what I'm doing wrong here?
I would like to work with pyautogui:
>>> import pyautogui
>>> pyautogui.PAUSE = 1
>>> pyautogui.FAILSAFE = True
>>> pyautogui.size()
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
pyautogui.size()
AttributeError: module 'pyautogui' has no attribute 'size'
Don't know why it doesn't show my resolution? And in general, pyautogui doesn't work with commands like:
>>> pyautogui.moveTo(100, 100, duration=0.25)
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
pyautogui.moveTo(100, 100, duration=0.25)
AttributeError: module 'pyautogui' has no attribute 'moveTo'
>>>
I'm sure I installed pip.
Your own script which is named "pyautogui.py" is interfering with the module you installed — so rename it something else.

pygame: from pygame.locals import * not working

In my code
from pygame.locals import *
gets the following error message:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from pygame.locals import *
ImportError: No module named 'pygame.locals'
I have ensured that I don't have any files named pygame.py or pygame.pyc in my working directory and I'm using Python3.3.5 and pygame-1.9.2a0-hg on Windows 10. Could there be any other reason for this error?
Using Pycharm. My python file was called pygame. When I copied and pasted the code into another python file with a different name, it worked. This is as new to me as anything.

Pygame installed, but not working

I am using a mac and i want to use pygame but it is not working.
this is the error i get when I try to do import pygame
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import pygame
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
Please help I am using python 2.7.9
If your file name is called pygame.py the system imports your python file.
If your file name is not pygame.py, you can try doing pip install pygame or python -m install pygame.

Categories

Resources