libraries and framework feature which makes even the difficult tasks easy. One similar library is Pygame which you can use to create fun and unique 2D games. In this article, we will discuss different ways to install Pygame on Windows OS.
Things to Do Before Installing Pygame on Windows
There are certain things you need to check before installing Pygame as they are important for successful installation. The first is finding out whether the Python app is available on your device or not. Follow these steps:
- Click on Start menu and go to “Search” option.
- Type “Command Prompt” and press “Enter” key.
- Once the Command Prompt window is open type the following command and press Enter.
- “python –version”
- If Python is present on your device you will be able to see the Python version. This means you are ready for the next step.
- In case the command does not run successfully then you need to install the latest version of Python on your device.
The next thing is to check for PIP installation. It is a tool use to install packages on Python. If you have Python with version 2.7.9+ or Python 3.4+ then PIP will automatically install with Python installation. To see whether PIP is available or not do the following steps:
- Open “Command Prompt” through Start Menu.
- Type this command and press the “Enter” key.
- “pip –version”
- If the command runs successfully then it is available on your device.
After you have successfully done both of the following, now you are ready to install Pygame on Windows.
Ways to Install Pygame on Windows
There are three main ways through which you can install Pygame and all of them are simple to follow through. All you need to do is adhere to the instructions given with each step in order and you can get Pygame in no time.
Installing Through PIP
The most basic and easiest way to install Pygame is via PIP. This is done by the majority of Windows users. Just do these steps:
- Press the “Win + R” key at the same time. This will open “Run” prompt window.
- Type “cmd” in the blank space and press “OK”.
- Wait for “Command Prompt” window to appear on your screen.
- Now type the following command and then press “Enter” key.
- “pip install pygame”
- Wait for the command to be executed
- Once done, verify the installation by creating a Python Scrip with this code.
- “import pygame”
- “print(“pygame version:”, pygame.__version__)
- If the code runs successfully then Pygame is install on your Windows device.
Installing With PyCharm
If you are more comfortable using PyCharm IDE then this method is especially for you. It is also for those who are facing issues with previous installation ways.
If you don’t have PyCharm on your device then you will need to open any web browser on your system. Now search for PyCharm’s official website to download it from. After downloading, install it on your system by following the given instructions.
- Launch PyCharm on your device.
- Create a new project by clicking on “File” option and selecting “New Project”.
- Now choose “Python” from the list of available options.
- In project settings, go to “Python” then “Python Interpreter”.
- After that, click on the “Plus” or “+” button to add a package.
- Look for “pygame” and then click on “Install Package” button.
- You have now successfully install Pygame on your system.
Installing via Source
Lastly, you can install Pygame through source code. This method is for those who have previously work with source code. If you are not familiar then try doing other methods.
- First of all, you need to download the pygame source.
- Launch your favorite web browser and click on the address bar.
- Search for the pygames official and press Search icon.
- On the website, locate “Source”.
- Here you will be able to find Pygame source code in zip or tag.gz file format.
- Once it is downloaded, extend the code to whatever location you like. Also, make sure to remember or note down this location.
- Now, open the Run prompt by pressing “Win and R” keys together.
- Type “cmd” and press “Enter”.
- In the Command Prompt window, use “cd” to locate the place you have to unzip the source code.
- For example “cd C:\Users\YourUsername\Desktop\pygame-1.9.6”.
- Now run these commands to build and install.
- “python setup.py build”
- “python setup.py install”
- Again wait for the command to finish executing.
You can check it is install on your system correctly by running a simple Pygame code.
- Create a Python project “pygame_test.py”.
- Now type the following code.
import pygame
pygame.init()
# Create a window
window = pygame.display.set_mode((400, 300))
# Run the game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Quit Pygame
pygame.quit()
- Run the script with the “python pygame_test.py” command.
- If a window appear then Pygame is successfully install on your Windows operating system.
Conclusion
Python is one of the best programming languages due to many reasons among which is its library and framework functionality. With this, you can have things like Pygame which tremendously helps with its simplicity and flexibility in 2D game development. If you want to learn more about it or different ways to install pygame on Windows then read the above article.
Read Also: How To Download YouTube Videos? YT Download