0

I am trying to learn Python and thought it would be more interesting to learn to write games but the difficult bit seems to be getting pygame to work.

I'm not really into IT so sorry this is a but rambling and I have probably left off some geeky stuff you need to know.

I have windows 10, which is 64bit, I installed python 2.7 and then tried to get pygame to work. When I open python it has c:\Python27\python.exe at the top of the screen and type help("modules") then it lists pygame. So it is there.

however I am following a book which is supposed to teach me to program but I am having problems starting.

It says to write a program in notepad which I saved in c:\user\user\firstprogram.py, the first line is

import pygame, sys

However when I go into the cmd prompt and put

python firstprogram.py 

Its error message is

Traceback File "Firstprogram.py", line 1, in import pygame, sys Modulenotfounderror: no module name 'pygame'

There are several possible reasons. Is it the version of pygame?

Do I need to tell python where pygame is and how do I do this, When should python and pygame be installed i.e. c:\ etc etc as searching google doesn't seem to tell me this.

1 Answer 1

1

please check your C:\ directory do you have any other python versions installed?

And I recommend you to do this.

1.) Open Python IDLE and write

import pygame

and then:

print(pygame.init())

If it returns

(6, 0)

Then that means that you have pygame installed.

2.) My advice is to not use notepad and run the .py from the command line since that is to much work and not efficient.

3.) In the python IDLE in the top-left corner click file and then NEW FILE, a window should pop up and this is where your code goes.. write

import pygame

print(pygame.init())

if you get the result

(6, 0)

4.) If that doesn't work then probably you do not have pygame installed. I suggest you install it through module "pip".

Here is a link that shows how to install pip https://pip.pypa.io/en/stable/installing/

When installed just open up a command prompt and write

pip install pygame

and pygame should be compiling without problems now.

Pygame works fine. Program in the python IDLE integrated IDE.

P.S

You can download any IDE for python and program from there its easier and more nice to program in. (Pycharm is my best choice).

Good Luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.