Pygame init ошибка

I downloaded pygame successfully but now when I do:

import pygame
pygame.init()
size =  [400, 400]

pygame.display.set_mode(size)

it gives errors:

Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module> pygame.init AttributeError:
'module' object has no attribute 'init'

And nothing is working for me. Please help me use init and display.

I am using

  • python 3.4.1 and
  • pygame 1.9.2 on
  • Windows 7 32bit and
  • I installed pygame on

    c://python34/include/
    

Gottlieb Notschnabel's user avatar

asked Aug 15, 2014 at 16:18

Paarth Tara's user avatar

1

You probably had named your file pygame.py
when you type:

import pygame

python won’t import pygame module you want, instead it will try import local module pygame — your file. and your file hasn’t method init.
try change file name from pygame.py to mypygame.py.

answered Aug 15, 2014 at 18:57

Marcin Fabrykowski's user avatar

2

I had the same problem, but then I reinstalled everything and realized that I had a different version of pygame than I needed for python

I realized also that I shouldn’t use the .zip archive to install. I looked in there and saw that there’s an installer for it if you’re on any major OS. For example, for Macintosh, there’s .dmg files. For Windows, there’s .msi, etc.

answered Aug 3, 2015 at 22:15

Drew Christensen's user avatar

You probably installed your pygame library in the include/ folder, but somehow didn’t have the correct files inside it. This may of happened because of some downloading issues or the website you were downloading from. Hope this helps! You want to type downloading pygame from pygame.org instead of some other places on the web because of possible errors or changes in code.

answered Oct 26, 2015 at 16:08

Paarth Tara's user avatar

Environment:

You can get some of this info from the text that pops up in the console when you run a pygame program.

  • Operating system (e.g. Windows, Linux(Debian), Linux(Ubuntu), Mac): Mac and Android (Pydroid 3)
  • Python version (e.g. 3.7.9, 3.8.5) : 3.10.4
  • SDL version (e.g. SDL 2.0.12): I don’t know
  • PyGame version (e.g. 2.0.0.dev10, 1.9.6): 2.1.2 (I see /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pygame-2.1.2.dist-info/)
  • Relevant hardware (e.g. if reporting a bug about a controller, tell us the brand & name of it): Intel CPU

Current behavior:
When I try to run a simple script, or when simply importing pygame, I get this error:

AttributeError: partially initialized module 'pygame' has no attribute 'init' (most likely due to a circular import)

Tried running with Python 3.6 using a docker image, but it faces the same error.

Expected behavior:
Initialize pygame and draw the game window

Screenshots

If applicable, copy and paste screenshots to help explain your problem.

Steps to reproduce:

Please explain the steps required to duplicate the issue, especially if you are able to provide a sample application.
if the bug is caused by a specific file (image, font, sound, level, please upload it as an attachment

  1. create a python script
  2. add «import pygame» to the file
  3. run the file

Test code

If possible add a simple test program that shows the problem described in this report.

Stack trace/error output/other error logs

Traceback (most recent call last):
  File "/Users/me/src/playground/pygame/test.py", line 1, in <module>
    import pygame
  File "/Users/me/src/playground/pygame/pygame.py", line 8, in <module>
    pygame.init()
AttributeError: partially initialized module 'pygame' has no attribute 'init' (most likely due to a circular import)

Asked
2 years, 11 months ago

Viewed
1k times

After I write «import pygame» no error comes up so I think I’m good to go but when I try to create a program and then I type «pygame.init()» an error comes when I run this code. I also ran this program in shell but it was working, no error was there. But I don’t know for some reason it doesn’t run when I try to create a program.

Traceback (most recent call last):
File «C:/Users/LENOVO/AppData/Local/Programs/Python/Python38-32/pygame.py», line 1, in
import pygame
File «C:/Users/LENOVO/AppData/Local/Programs/Python/Python38-32pygame.py», line 2, in
pygame.init()
AttributeError: partially initialized module ‘pygame’ has no attribute ‘init’ (most likely due to a circular import)

This is the error I am getting when I try to open a window in pygame and this is the code I wrote:

import pygame
pygame.init()

win = pygame.display.set_moode((500, 500))

Rabbid76's user avatar

Rabbid76

200k26 gold badges129 silver badges171 bronze badges

asked Jun 4, 2020 at 13:48

1

The problem is that you named your game’s source file pygame.py. That causes import pygame to import that very file itself, rather than the actual pygame library.

Just rename the file to something else!

answered Jun 4, 2020 at 14:12

Thomas's user avatar

ThomasThomas

173k48 gold badges354 silver badges475 bronze badges

3

Pygame — это библиотека для разработки игр, написанная на языке программирования Python. Но, как и любое программное обеспечение, у неё могут быть ошибки. Одна из таких ошибок — это ошибка init, которая может возникать при запуске Pygame. В этой статье мы разберём причины возникновения этой ошибки и научимся её решать.

Причины ошибки init в Pygame

Ошибки init в Pygame могут возникать по разным причинам. Рассмотрим наиболее распространённые из них:

  1. Отсутствие установленного Pygame. Для работы с этой библиотекой требуется установить её на компьютер. Если вы попытаетесь запустить программу без установленного Pygame, то может возникнуть ошибка init.

  2. Неисправность установленного Pygame. Если библиотека была неправильно установлена, то это может привести к возникновению ошибки init.

  3. Несовместимость версий Pygame и Python. Если версии этих двух компонентов не совместимы, то это также может привести к ошибке init в Pygame.

Решение ошибки init в Pygame

Если у вас возникла ошибка init в Pygame, то не отчаивайтесь — она может быть легко исправлена. Рассмотрим несколько способов решения этой проблемы:

  1. Проверьте, установлен ли Pygame на вашем компьютере. Если он не установлен, то загрузите его с официального сайта Pygame и установите на свой компьютер.

  2. Проверьте, не повреждён ли ваш установленный Pygame. Если это так, то выполните переустановку библиотеки.

  3. Убедитесь, что версии Pygame и Python совместимы друг с другом. Если это не так, то загрузите подходящую версию Pygame для вашей версии Python.

  4. Настройте вашу среду разработки. Если вы используете IDLE, то попробуйте запустить вашу программу в консоли.

Выводы

Ошибки init в Pygame могут возникать по разным причинам, но, как правило, они являются легко исправляемыми. Если вы столкнулись с этой ошибкой, то следуйте рекомендациям, описанным в этой статье, и вы решите проблему в кратчайшие сроки. Pygame — отличная библиотека для разработки игр, и никакие ошибки не должны отвлекать вас от её использования.

  • Rafi1

AttributeError: module ‘pygame’ has no attribute ‘init’
Как решить проблему?


  • Вопрос задан

    более трёх лет назад

  • 3201 просмотр

Удалите или переименуйте папку которая называется pygame в пути
И удалите файлы которые называются pygame.py в Documents, это всё «маскируется» под реальные настоящие модули
Не называйте так файлы и папки, они не должны начинаться с pygame

Пригласить эксперта


  • Показать ещё
    Загружается…

04 июн. 2023, в 12:23

30000 руб./за проект

04 июн. 2023, в 12:18

20000 руб./за проект

04 июн. 2023, в 12:07

2000 руб./за проект

Минуточку внимания

Понравилась статья? Поделить с друзьями:
  • Pygame error font not initialized ошибка
  • Pyflakes e ошибка
  • Pycrypto python ошибка
  • Pycharm ошибка сертификата
  • Pycharm ошибка при запуске