Pygame... first tutorial help!

Started by
13 comments, last by cherokee596 16 years, 5 months ago
I'm on Windows Vista...I can import Pygame into Python, check the directory, make and name a window, but I can't load the monkey head image...I get an error saying: Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> monkey_surface = pygame.image.load(monkey_head_file_name) error: Couldn't open data\chimp.bmp
Advertisement
Guess what? It can't find the image file. ;)

Where did you store the file and from where do you run the game? Also, which tutorial are you following?
Create-ivity - a game development blog Mouseover for more information.
I'm trying to run it from the Python shell. The file "examples" is on my desktop. I'm using the third part of the tutorial "An introduction to Python game programming".
Quote:Original post by cherokee596
I'm trying to run it from the Python shell. The file "examples" is on my desktop. I'm using the third part of the tutorial "An introduction to Python game programming".


Desktop huh?
Move your media files and source to your main HDD drive (c:\).
Then update "monkey_head_file_name" variable with the new path(eg C:\mygame\data\monkeyhead.bmp") and try again.
I tried making a path...however I am totally Dos-ignorant. So, I tried to reinstall the programs, and I think I came across my error. When I installed Pygame before, I ignored the warning messages that said, in sequence: 1)could not create (Pygame) 2)Could not set key value (" ") 3)Could not set key value (" ") then, in effect... "installing program REMOVE PYGAME"

Is that what is going on? Pygame won't install correctly on my computer??? Because I have Windows Vista? I don't know...

well, I thank you for your help...do you think this could be the problem, or am I completely mislead?
Quote:Original post by cherokee596
I tried making a path...however I am totally Dos-ignorant. So, I tried to reinstall the programs, and I think I came across my error. When I installed Pygame before, I ignored the warning messages that said, in sequence: 1)could not create (Pygame) 2)Could not set key value (" ") 3)Could not set key value (" ") then, in effect... "installing program REMOVE PYGAME"

Is that what is going on? Pygame won't install correctly on my computer??? Because I have Windows Vista? I don't know...

well, I thank you for your help...do you think this could be the problem, or am I completely mislead?

I've used Python and pygame on Vista without a problem so I don't think Vista is your problem.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Not a problem with Windows Vista, huh. Well I've tried to run the program
1)Ok...starting at the first tutorial "An Introduction to Python Game Programming" in the First Lecture...in the section called "Running the Chimp" at the windows prompt (in the Command Prompt)I type in:


C:\Windows>set PATH=%PATH%;c:\Python25\cd "\Program Files\examples"


and I just get back: C:\Windows>


Now, I put the file "examples" on the hard drive under "Program Files"...so what am I doing wrong?


2)Next, in the Third Lecture I: imported the modules,initialized pygame, set up the screen,constructed the monkey filename, and then attempted to load the Monkey Head Image with:


monkey_surface = pygame.image.load(monkey_head_file_name)


Getting the message:
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
monkey_surface = pygame.image.load(monkey_head_file_name)
error: Couldn't open data\chimp.bmp




I'm still lost...and I've probably worn you out with my inefficiency. Oh well.
So, you're running these scripts from the IDLE console? That's probably where things go wrong. Try this: type 'import os', then type 'print(os.getcwd())'. This will tell you which directory Python is currently looking in.

If that is something like 'C:\Program Files\Python', and if you're trying to load 'data\chimp.bmp', then the pathname of the file will be 'C:\Program Files\Python\data\chimp.bmp'. If 'chimp.bmp' is stored somewhere else, then you'll get an error telling you the file could not be loaded.


For your information, Python scripts can be executed in multiple ways. You can type your code directly into the Python shell or the IDLE GUI. You can also store your scripts in .py files, and tell Python to execute them. This can be done by starting Python from the command line and passing the filename as an argument, but also by dragging your file onto the Python executable icon (which, underwater, does exactly the same). Also, you can make Windows associate the .py extention with Python, so clicking on a .py file will automatically start Python, telling it to execute that file (again, underwater, this starts Python and passes the filename as an argument).

In other words, you don't need to run your scripts from the console.
Create-ivity - a game development blog Mouseover for more information.
Quote:Original post by cherokee596
C:\Windows>set PATH=%PATH%;c:\Python25\cd "\Program Files\examples"

That's a bad path, for starters.

PATH is an environment variable. Bring up a console window, then type echo %PATH% and hit enter. You'll see a bunch of text which represents different directories on your system that Windows should search when you type a program name. Each directory is separated from the next by a semicolon. Your very first problem is that you're trying to attach a non-directory command (cd "\Program Files\examples") to your path.

So, if your Python installation is located at C:\Python25, then you want to do this instead:
C:\Windows> set PATH=%PATH%;C:\Python25

and hit enter. The portion in bold is called the system prompt, and will always appear as the first thing on the line. The directory will change to reflect your current directory, and your input will begin after the greater-than symbol and a single space.

Quote:and I just get back: C:\Windows>

When you issue the CMD.EXE command set, it creates or modifies an environment variable but generates no other output. Consequently, the next thing you will see will be the system prompt at the current directory. You then want to change your current directory in a separate step. If you have installed the PyGame example to C:\Program Files\examples, then type:
C:\Windows> cd "\Program Files\examples"

and hit enter. The current directory will be changed (the command cd stands for change directory), and you will receive a new, updated prompt:
C:\Program Files\examples> 


Now, under your examples directory there should be another directory named data. You can get a list of the contents of examples like this:
C:\Program Files\examples> dir

Pressing enter will ask the system to retrieve a directory listing. You should see a bunch of stuff fill up the screen; pay attention to the last column on the right for now, and check to see if anything is named "data" (the case doesn't matter; it may be "Data" or "DATA", or any other variation).

You can also check to see what's inside the data directory:
C:\Program Files\examples> dir data

Check to make sure the file chimp.bmp is listed.

If you've found your directory and bitmap image file, then simply run the script from the command line. If you've associated .py files with the Python interpreter, you can simply type:
C:\Program Files\examples> chimp.py

and press enter. If you haven't, then you'll need to explicitly invoke the Python interpreter:
C:\Program Files\examples> python chimp.py

The system knows where to find "python" (actually python.exe; it automatically tries the .exe, .bat and .com extensions) because you added C:\Python25 to your path earlier, and the full path to the interpreter is C:\Python25\python.exe.

Hope that helps.

This topic is closed to new replies.

Advertisement