1

I have pygame on xubuntu, on Python 3.5. I am trying to run my first code.

import pygame

pygame.init()

I have:

AttributeError                            Traceback (most recent call last)
<ipython-input-11-9f5fb6a2d879> in <module>()
  1 import pygame
  2 
 ----> 3 pygame.init()
  4 

AttributeError: module 'pygame' has no attribute 'init'

And:

pygame.__path__

I have:

NamespacePath(['/home/agnieszka/Pulpit/Python/pygame'])

You have a print screen here:

enter image description here

I have my script saved in: "/home/agnieszka/Pulpit/Python/", so pygme was installed in the same place.

What is wrong? I believe, you will know...

The name of the file is program.py:

agnieszka@agnieszka-xubuntu:~/Pulpit$ cd /home/agnieszka/Pulpit/Python/
agnieszka@agnieszka-xubuntu:~/Pulpit/Python/home/agnieszka/anaconda3/bin/python program.py
Traceback (most recent call last):
File "program.py", line 3, in <module>
pygame.init()
AttributeError: module 'pygame' has no attribute 'init'

EDIT: the output, you asked for:

agnieszka@agnieszka-xubuntu:~/Pulpit/Python/pygame$ ls -lh     /home/agnieszka/Pulpit/Python/
razem 24K
drwxrwxr-x  3 agnieszka agnieszka 4,0K paź 31 10:52 GRA
drwxrwxr-x  4 agnieszka agnieszka 4,0K paź 30 13:04 laborki
drwxrwxr-x  7 agnieszka agnieszka 4,0K paź 18 08:22 padpy1617
drwxrwxr-x  2 agnieszka agnieszka 4,0K paź 30 13:04 prace_domowe
-rw-rw-r--  1 agnieszka agnieszka   29 paź 31 11:01 program.py
drwxrwxr-x 18 agnieszka agnieszka 4,0K paź 31 11:27 pygame

EDIT: After adding:

print(dir(pygame))

I have:

 agnieszka@agnieszka-xubuntu:~/Pulpit/Python$ /home/agnieszka/anaconda3/bin/python program.py
 ['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
ChrisB
  • 2,497
  • 2
  • 24
  • 43
AgnieszkaTomczyk
  • 253
  • 2
  • 12
  • 1
    Don't post a link to a picture of your code. Post your actual code here, as text. – Daniel Roseman Oct 31 '16 at 09:37
  • Of course, done :) – AgnieszkaTomczyk Oct 31 '16 at 09:45
  • You say you saved your script (though I see IPython output); what name did you give that script? –  Oct 31 '16 at 09:52
  • Btw, is there no default installation for pygame for Python 3? Either along the lines of `sudo apt-get install python3-pygme` or `python3.5 -m pip install pygame` (without sudo, pip will likely install it in $HOME/.local). That's nicer than in non-common directory. –  Oct 31 '16 at 09:54
  • please post the output of `ls -lh /home/agnieszka/Pulpit/Python/` – Guillaume Oct 31 '16 at 10:15
  • I used instructions for Python 3.x from: http://www.pygame.org/wiki/CompileUbuntu?parent=Compilation , without any change. – AgnieszkaTomczyk Oct 31 '16 at 10:26
  • You could also do a `print(dir(pygame))` to see what functions actually are callable. – pingul Oct 31 '16 at 10:32
  • 1
    hum, very strange indeed. And a `ls -lh /home/agnieszka/Pulpit/Python/pygame/` ? – Guillaume Oct 31 '16 at 11:05
  • 1
    did you use `pygame` as filename or directory name ? Then now Python imports this file/folder instead of oryginal `pygame` module and it can't find `init()` in your file/directory. – furas Oct 31 '16 at 12:15
  • 2
    BTW: this summer PyGame authors create new packages for Linux so now you can install it using `pip`, `pip3` – furas Oct 31 '16 at 12:17
  • 1
    after `import pygame` print `pygame.__file__` and you see which file is imported. – furas Oct 31 '16 at 12:18
  • BTW: see groups on Facebook: [Python: Pierwsze kroki](https://www.facebook.com/groups/pythonpierwszekroki/) and [Python Poland](https://www.facebook.com/groups/pythonpl/) – furas Oct 31 '16 at 12:22
  • Thank you! pip was helpful :) – AgnieszkaTomczyk Nov 06 '16 at 18:27

0 Answers0