Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to find the pygame example files?
#1
Hello.

Pygame has examples. On their website, stands this:

To get the files, run this code in the python interpreter:

>>> import pygame.examples.scaletest
>>> pygame.examples.scaletest.__file__
'/usr/lib/python2.6/site-packages/pygame/examples/scaletest.py'

I wanted to have the files for examples.aliens.
I've replaced the code above, by:


import pygame.examples.aliens
pygame.examples.aliens.__file__
'/usr/lib/python2.6/site-packages/pygame/examples/aliens.py'

Every time, I run it, nothing happens. It just says: Welcome to the pygame community: (Link to pygame website).
Nothing else happens.

So how can I find out, where those files are saved? Thanks for your help.

Piethon
Quote
#2
Its meant to be ran from the command prompt/terminal, not imported into the interpreter.

metulburr@ubuntu:~$ python -m pygame.examples.aliens
metulburr@ubuntu:~$ 
in which it will run the example program

The way you have it is showing where the file are located:
/usr/lib/python2.6/site-packages/pygame/examples/aliens.py
navigate there and you can see the files

P.S. Python2.x has an end of life support coming up in Jan 1st 2020.; I would suggest to start using python3.x
Quote
#3
(Sep-03-2019, 11:14 AM)metulburr Wrote: The way you have it is showing where the file are located:
/usr/lib/python2.6/site-packages/pygame/examples/aliens.py
navigate there and you can see the files

P.S. Python2.x has an end of life support coming up in Jan 1st 2020.; I would suggest to start using python3.x

1: I moved there, and there is no folder called pygame.
2: I have a mac, where 2.7 is pre-installed, and I am using 3.7 for my projects. But when I move to the library, there is just a folder called 2.7 none with 3.7.
Quote
#4
the pygame folder would be in this path. I am not sure where you moved to? By importing that example yourself you got that path, so it must be there.
/usr/lib/python2.6/site-packages/


Libraries you install should be in /usr/local/lib, not /usr/lib. Look for python versions you installed there. Im pretty sure that Macs use the linux file structure for the most part.

If you cant find it run the whereis command on it to find its location
metulburr@ubuntu:~$ whereis python3.6
python3: /usr/bin/python3.5m /usr/bin/python3.5-config /usr/bin/python3.5m-config /usr/bin/python3 /usr/bin/python3.7 /usr/bin/python3.5 /usr/bin/python3.7m /usr/lib/python3 /usr/lib/python3.7 /usr/lib/python3.6 /usr/lib/python3.5 /etc/python3 /etc/python3.7 /etc/python3.6 /etc/python3.5 /usr/local/bin/python3.6-config /usr/local/bin/python3.6m-config /usr/local/bin/python3 /usr/local/bin/python3.6 /usr/local/bin/python3.6m /usr/local/lib/python3.7 /usr/local/lib/python3.6 /usr/local/lib/python3.5 /usr/include/python3.5m /usr/include/python3.6 /usr/include/python3.5 /usr/include/python3.6m /usr/share/python3 /usr/share/man/man1/python3.1.gz
metulburr@ubuntu:~$ whereis python2.7
python2: /usr/bin/python2.7 /usr/bin/python2.7-config /usr/bin/python2 /usr/lib/python2.7 /etc/python2.7 /usr/local/lib/python2.7 /usr/include/python2.7 /usr/share/man/man1/python2.1.gz
metulburr@ubuntu:~$ whereis python3.7
python3: /usr/bin/python3.5m /usr/bin/python3.5-config /usr/bin/python3.5m-config /usr/bin/python3 /usr/bin/python3.7 /usr/bin/python3.5 /usr/bin/python3.7m /usr/lib/python3 /usr/lib/python3.7 /usr/lib/python3.6 /usr/lib/python3.5 /etc/python3 /etc/python3.7 /etc/python3.6 /etc/python3.5 /usr/local/bin/python3.6-config /usr/local/bin/python3.6m-config /usr/local/bin/python3 /usr/local/bin/python3.6 /usr/local/bin/python3.6m /usr/local/lib/python3.7 /usr/local/lib/python3.6 /usr/local/lib/python3.5 /usr/include/python3.5m /usr/include/python3.6 /usr/include/python3.5 /usr/include/python3.6m /usr/share/python3 /usr/share/man/man1/python3.1.gz
Quote
#5
If I use the whereis command, the output looks like this:

whereis python2.7
/usr/bin/python2.7
MyMacBookAir:~ piethon$ whereis python3.7
MyMacBookAir:~ piethon$ whereis python3.6
MyMacBookAir:~ piethon$ 

It tells me where Python 2.7 is, but not, where python 3.7 is. Eh...? Python2 is preinstalled. I installed python3.7 from the official website. In my applications folder, I have a ptyhon3.7 folder.
But in there, are just the following things:

IDLE
InstallCertifications.command
License.rtf
PythonDocumentation.html
PythonLauncher
ReadMe.rtf
Update Shell profile.command
Quote
#6
im not really sure then where macs put things. I never have used or would ever use one.

I would then use python itself to tell me where it is
1) open the interpreter you want to use python 3.7 which i am assuming on a mac would be invoking it like:
python3.7
or maybe even
python37
then run sys.path to find its location
metulburr@ubuntu:~$ python3.7
Python 3.7.3 (default, Mar 26 2019, 01:59:45) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages', '/usr/lib/python3/dist-packages']
>>> 

That would give you the correct location of the paths for that specific python version to find the example files

In my case i would install pygame to my python3.7 via
metulburr@ubuntu:~$ python3.7 -m pip install pygame
Collecting pygame
  Downloading https://files.pythonhosted.org/packages/18/b3/0bf5afdcf6ef95d2a343cd7865585a6efe5e3e727c1a4f3385c9935248cf/pygame-1.9.6-cp37-cp37m-manylinux1_x86_64.whl (11.4MB)
    100% |████████████████████████████████| 11.4MB 153kB/s 
Installing collected packages: pygame
Successfully installed pygame
confirmation:
metulburr@ubuntu:~$ python3.7
Python 3.7.3 (default, Mar 26 2019, 01:59:45) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
examples execution:
metulburr@ubuntu:~$ python3.7 -m pygame.examples.aliens
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
EDIT:
after installing mine, it installed pygame to this path in my home.
metulburr@ubuntu:~/.local/lib/python3.7/site-packages/pygame/examples$ ls
aacircle.py      fonty.py                       playmus.py
aliens.py        freetype_misc.py               prevent_display_stretching.py
arraydemo.py     glcube.py                      __pycache__
audiocapture.py  headless_no_windows_needed.py  scaletest.py
blend_fill.py    __init__.py                    scrap_clipboard.py
blit_blends.py   liquid.py                      scroll.py
camera.py        macosx                         sound_array_demos.py
chimp.py         mask.py                        sound.py
cursors.py       midi.py                        stars.py
data             moveit.py                      testsprite.py
dropevent.py     oldalien.py                    textinput.py
eventlist.py     overlay.py                     vgrade.py
fastevents.py    pixelarray.py                  video.py
Quote
#7
So I've opened VS Code, and made a file called findthing.py, that looked like this:

import sys
sys.path
['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages', '/usr/lib/python3/dist-packages']
Then I ran the code with "python3.7 findthing.py" (on the same path) and nothing happened. Do you think that uninstalling pygame and then installing it on the python3.7 path, would be an option?
(I've installed it with "pip3 install pygame", so I think, it should be installed for 3.7, but I can't find it).
Quote
#8
(Sep-03-2019, 02:09 PM)Piethon Wrote: Do you think that uninstalling pygame and then installing it on the python3.7 path, would be an option?
pygame installed to any other version means nothing when you are running it from another version it is installed to. Each python version needs its own separate pygame.

(Sep-03-2019, 02:09 PM)Piethon Wrote: pip3 install pygame
This does not necessarily install it to python3.7. Do you have any other python3.x versions?

What is pip3 pointing to? The output will have the version, but also which python version it is installing things to.
pip3 -V
Output:
metulburr@ubuntu:~$ pip3 -V pip 19.2.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
This is why you might want to install it via
python3.7 -m pip install pygame
to make sure it is installing to python3.7
Quote
#9
(Sep-03-2019, 05:13 PM)metulburr Wrote:
(Sep-03-2019, 02:09 PM)Piethon Wrote: pip3 install pygame
This does not necessarily install it to python3.7. Do you have any other python3.x versions?

What is pip3 pointing to? The output will have the version, but also which python version it is installing things to.
pip3 -V
Output:
metulburr@ubuntu:~$ pip3 -V pip 19.2.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

I just have python 3.7 and python 2.7.

What is it pointing to? This:

pip 19.2.2 from /Users/piethon/Library/Python/3.7/lib/python/site-packages/pip (python 3.7)

3.7
Quote
#10
in that case pip3 install pygame should install it to python3.7

run that interpreter in the terminal first to verify pygame is working. Not in VS Code or any other IDE.
metulburr@ubuntu:~$ python3.7
Python 3.7.3 (default, Mar 26 2019, 01:59:45) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> 
then try it in VS Code. Make sure that is invoking the python3.7 version
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)