How to install Pygame in Sublime Text
Pygame is a Python library for creating 2D games. To install Pygame in Sublime Text, follow these steps:
#1. Install Python
Make sure Python 3 is installed. You can download and install it from the official Python website.
2. Install pip
pip is Python’s package management system. If it is not installed yet, please use the following command to install it:
<code>python -m ensurepip --upgrade</code>
3. Use pip to install Pygame
Open a terminal or command prompt and use the following command to install Pygame:
<code>pip install pygame</code>
4. Add the Pygame path to the environment variable
Now you need to add the Pygame installation path to the system environment variable. This way Sublime Text can find it. In Windows, do the following:
<code>C:\Python3\Lib\site-packages</code>
In macOS and Linux, do the following:
<code>export PYTHONPATH=$PYTHONPATH:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages</code>
(Adjust the version number according to your Python installation location)
5. Verify installation
Open Sublime Text, press Ctrl
~
(Windows) or Cmd
~
(macOS) to open the console . Then, run the following command:
<code>import pygame pygame.init() print(pygame.get_init())</code>
If the output is [True, True, True, True, True, True, True, True, True, True, True, True]
, that means Pygame has been installed successfully.
The above is the detailed content of How to install pygame in sublime. For more information, please follow other related articles on the PHP Chinese website!