-->

Welcome to our Coding with python Page!!! hier you find various code with PHP, Python, AI, Cyber, etc ... Electricity, Energy, Nuclear Power

Tuesday, 3 July 2018

Python | How to install PyGame for Python 3


PyGame is a set of python modules designed for writing games. It uses the SDL library to allow you to create games and multimedia programs in Python. PyGame is highly portable and runs on nearly every platform and operating system. The SDL library, or Simple DirectMedia Layer is a development library written in that provides low-level access to audio, keyboard, mouse, joystick and graphics hardware. PyGame is what allows us to use SDL with Python.

Python install
If you don’t already have Python3 installed download it from http://www.python.org/downloads/
Make sure you pick the correct installer for your computer, e.g. Windows x86 or Windows x64 or Mac, etc.
When running the installer it should place the installation in the default location, for Python3 version 3.4 on Windows this is:
C:\python34
On Mac OSX it is:
/usr/local/bin/python
On Windows, make sure Python is added to the system path by opening the command prompt (ΓΏ+ R, ‘cmd’) and type
set path=%path%;C:\python34
Where 34 is equal to your Python 3 version number.
Check the Python 3 install
To check that Python has installed correctly open the command prompt or terminal and simply type
python
If this causes an error, then Python has not installed correctly. If it does not, you should see a new python prompt that looks like this:
>>> 
To exit the Python prompt, press Ctrl + z, then press the Enter key. Then exit the command prompt or terminal.
If you chose you can install a Python IDE or Python editor at this point, before continuing on.
PyGame install
When Python is installed and confirmed to be working you can install PyGame.
For Windows installs:
You can download PyGame from http://www.pygame.org/download.shtmlThe version of PyGame to use depends on your version of Python. For example, if you have Python 3.4 installed then the PyGame installer name you need to download will include ‘py3.2’
http://www.htmlpublish.com/newTestDocStorage/DocStorage/ae212c5255bc4891beef0dd44fdd4ce6/How-to-install-PyGame-for-Python-3%5B1%5D_images/How-to-install-PyGame-for-Python-3%5B1%5D2x1.jpg
For example for Windows:
pygame-1.9.2a0.win32-py3.2.msi
If your Python version is more recent than any mentioned by the installers available on the PyGame website you should check http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame for a later installer build. Again, make sure the version you download matches your operating system e.g. Windows x86 or Windows x64 or Mac OSX.
On Windows, run the installer and allow it to install PyGame in it’s default directory.
On Mac OSX:
Create and add the following to ~/.bash_profile:
# Homebrew binaries now take precedence over Apple defaults
export PATH=/usr/local/bin:$PATH
Install Apple Xcode command line tools:
xcode-select --install
Install XQuartz: http://xquartz.macosforge.org/landing/
Install homebrew:
ruby -e "$(curl –fsSLhttps://raw.github.com/Homebrew/homebrew/go/install)"
Install Python3 "proper" and packages we’ll need for installing PyGame from bitbucket:
brew install python3 hg sdl sdl_image sdl_mixer sdl_ttf portmidi
Install PyGame:
pip3 install hg+http://bitbucket.org/pygame/pygame
Restart the Mac for XQuartz changes
Check the PyGame install
Open a terminal or command prompt again (remember how you did this previously in the “Check the Python 3 install” section). At the Python prompt type:
import pygame
print(pygame.ver)
And then press the Enter key. This should then print the PyGame version number. If it does not or typing either of the above lines produces an error then PyGame is not correctly installed.
When everything is properly installed and working OK, you can go ahead and check out the PyGame Hello World Programme sheet.

No comments:

Post a Comment

Thanks for your comments

Rank

seo