Какую версию python поддерживает pygame

GettingStarted — wiki

Pygame requires Python; if you don’t already have it, you can download it from python.org. Use python 3.6.1 or greater, because it is much friendlier to newbies, and additionally runs faster.

The best way to install pygame is with the pip tool (which is what python uses to install packages). Note, this comes with python in recent versions. We use the —user flag to tell it to install into the home directory, rather than globally.

python3 -m pip install -U pygame --user

To see if it works, run one of the included examples:

python3 -m pygame.examples.aliens

Further information if you need it.¶

Hopefully the installation instructions above worked for you. If not, please read some alternative installation methods, and extra details below.

Wheels are available for x86 and x64 architectures on Linux and Windows, and for x64 on Mac. If pip doesn’t find a wheel for your platform, it will try to compile pygame from source (see below).

Читайте также:  Data to csv python pandas

pygame requires a «newer» pip. If pygame starts compiling from source and fails, first try upgrading pip.

Raspberry Pi¶

This comes with pygame already installed on the default raspbian installation.

Windows installation¶

Make sure you install python3.6 with the «Add python 3.6 to PATH» option selected. This means that python, and pip will work for you from the command line.

There is documentation with python for the «windows installation steps»

py -m pip install -U pygame --user
py -m pygame.examples.aliens

If you get ‘PermissionError: [WinError 5] Access is denied’, before starting the command prompt right click and «Run as administrator».

Mac installation¶

virtualenv issue¶

and pygame on mac, where it loses focus. More details here: details on the virtualenv issue. It does work if you create a venv with python -m venv however. Instructions if you want to use an virtualenv (some people have trouble with the window losing focus when inside a venv).

# create a virtualenv called 'anenv' and use it. python3 -m virtualenv anenv . ./anenv/bin/activate # venvdotapp helps the python be a mac 'app'. So the pygame window can get focus. python -m pip install venvdotapp venvdotapp python -m pip install pygame # See if pygame works with the oo module, and the aliens example. python -m pygame.examples.aliens

That’s just needed on mac if you use virtualenv, not if you install it with —user, or if you use -m venv.

Anaconda Mac¶

(note the w on the end). If it doesn’t work for you, please see the /wiki/MacCompile instructions.

Unix Binary Packages¶

Many Linux and BSD distributions have their own packages of Pygame. These may have an older version of Pygame than the wheels, but have been carefully tested with other packages in that distribution.

Debian/Ubuntu/Mint¶

sudo apt-get install python3-pygame
python3 -m pygame.examples.aliens

Fedora/Red hat¶

sudo yum install python3-pygame
python3 -m pygame.examples.aliens
Distribution Python 3 package Python 2 package Debian/Ubuntu python3-pygame python-pygame Fedora python3-pygame pygame

FreeBSD also has an active pygame package. While techinicaly it isn’t binary, it is automatically built and installed by the ports manager. See the FreeBSD package page for more information. http://www.freebsdports.info/ports/devel/py-game.html

Gentoo has a builtin package for pygame. This is compiled for your system as it installs, similar to BSD, http://packages.gentoo.org/package/dev-python/pygame

Installing From Source¶

Compilation¶

Compiling and installing pygame is handled by Python’s distutils. Pygame also comes with some scripts to automatically configure the flags needed to build pygame. Use the «setup.py» script to start the installation.

The first time you run the setup script, it will call the «config.py» script. This will build a «Setup» file which stores all the information needed to compile. The «config.py» will do a good job of detecting what dependencies are available and where they are located. If it isn’t perfect, it is easy to build your own, or edit the created «Setup» text file. This «Setup» file is a simple Makefile-like text file. It defines variables needed to use each dependency, and then enables all the pygame modules with found dependencies. If you have trouble compiling, you should be able to easily fix any problems inside the «Setup» file.

Running the «setup.py» script will call distutils to build and install the pygame package. Distutils actually supports a wide variety of compile and install options. running «python setup.py help» will start to show you the different options available. You can change many things like install locations, compiler to use, and more. Calling the «setup.py» script with no arguments and it will just ask you if you want the default flags needed to compile and install.

Some of the .c files are generated by Cython from .pyx files. Running «setup.py cython» will update them.

Windows Compiling Info

You can compile pygame on windows with mingw (gcc for windows) and also with visual studio. Up to date details can be found here: CompileWindows

Unix Compiling Info

Compiling from linux shouldn’t give you any problems. One thing you must keep in mind is that most linux RPM packages separate the actual library from the «dev» files needed to compile. To build you will need to make sure the packages like «SDL-dev» are installed.

You can check to see if SDL is ready to be built from by running the command sdl-config and seeing if it is found. If the sdl-config script is not on the path (or you have more than one?) Set the environment variable SDL_CONFIG to its location.

Sometimes you will have the SDL libraries installed in once location, and the other SDL libraries in another. This tricks the pygame config scripts, but you can help it out by setting the environment LOCALBASE to a path prefix where the other libraries are. The common case for this is SDL installed in /usr and other SDL libs installed in /usr/local. The command for this situation is «LOCALBASE=/usr/local python setup.py install«.

sudo apt install libsdl2-dev libfreetype6-dev libsdl2-mixer-dev libsdl2-image-dev libsdl2-ttf-dev libjpeg-dev libpng-dev libportmidi-dev python3 setup.py install --user # or "sudo python3 setup.py install" for a system-wide install 

Mac OS X Compiling Info¶

Up to date instructions for compiling on Mac OS X can be found here: MacCompile

Источник

How To Install Python Pygame Module Correctly

This article will tell you how to install the Python Pygame module correctly and how to fix the problems during the installation process.

1. Install Python Pygame Module Use The PIP Install Command.

$ pip install pygame Collecting pygame Downloading pygame-2.1.2-cp37-cp37m-macosx_10_9_x86_64.whl (8.9 MB) |████████████████████████████████| 8.9 MB 1.2 MB/s Installing collected packages: pygame Successfully installed pygame-2.1.2
$ pip show pygame Name: pygame Version: 2.1.2 Summary: Python Game Development Home-page: https://www.pygame.org Author: A community project. Author-email: [email protected] License: LGPL Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages Requires: Required-by:

2. Install Python Pygame Module Use The Binary Installer File.

  1. Besides using the pip install command, we can also install it using the downloaded binary installer file.
  2. Go to the Pygame GitHub website to download the Pygame installer file that matches your OS and Python versions.
  3. Open a terminal and go to the Pygame installer downloaded directory.
  4. Run the command python -m pip install –user pygame-2.1.2-cp37-cp37m-macosx_10_9_x86_64.whl to install the Pygame from the installer file.
$ python -m pip install --user pygame-2.1.2-cp37-cp37m-macosx_10_9_x86_64.whl Processing ./pygame-2.1.2-cp37-cp37m-macosx_10_9_x86_64.whl Installing collected packages: pygame Successfully installed pygame-2.1.2
$ python -m pygame --version pygame 2.1.2 (SDL 2.0.18, Python 3.7.3) Hello from the pygame community. https://www.pygame.org/contribute.html /Library/Frameworks/Python.framework/Versions/3.7/bin/python: No module named pygame.__main__; 'pygame' is a package and cannot be directly executed

3. How To Fix The ImportError: No module named ‘pygame’.

3.1 Question.

  1. I installed pygame 1.9.2 in Windows, and my python version is 3.5. But when I import the pygame module in the python source code, it shows the error ImportError: No module named ‘pygame’. How can I fix this error?
>>> import pygame Traceback (most recent call last): File "", line 1, in import pygame ImportError: No module named 'pygame'

3.2 Answer1.

  1. Below are the steps to install Pygame 1.9.2 on Python 3.5.1 for Windows, you can try it.
  2. After you successfully install Python 3.5, you should write down the Python 3.5 installed folder for later use.
  3. Download the wheel filepygame-1.9.2a0-cp35-none-win32.whl and save it to the folder python35/Scripts.
  4. Open a dos window and cd to the python35/Scripts folder, then run the below command.
pip3 install pygame-1.9.2a0-cp35-none-win32.whl
python -m pip install pygame-1.9.2a0-cp35-none-win32.whl

3.3 Answer2.

  1. I also meet such an error, but the reason is different.
  2. I installed multiple Python versions on my Windows, and I installed pygame library successfully into one of my Python versions.
  3. But my IDE used python interpreter does not contain the pygame library, so when I import pygame in my IDE the error is shown.
  4. After I select the python interpreter that has installed pygame library, the error disappear.
  5. wish this can help you too.

3.4 Answer3.

  1. This error happened when you do not install pygame successfully.
  2. Or you may have multiple Python versions installed, and pygame is installed in one of the python versions, but you import pygame in another python version.
  3. So you should make sure the pygame library has been installed in your python env, you can run the below command to check it.
(MyPythonEnv) C:\Users\zhaosong>pip show pygame Name: pygame Version: 2.1.2 Summary: Python Game Development Home-page: https://www.pygame.org Author: A community project. Author-email: [email protected] License: LGPL Location: c:\users\zhaosong\anaconda3\envs\mypythonenv\lib\site-packages Requires: Required-by:

4. How To Fix ERROR: Command errored out with exit status 1:…EOFError: EOF when reading a line When Install Pygame Using PIP.

4.1 Question.

  1. I run the command pip install pygame on windows 10, but it throws the error with the message ERROR: Command errored out with exit status 1:…EOFError: EOF when reading a line. My python version is 3.9. Below is the detailed error message. How can I fix it?
Collecting pygame Using cached pygame-1.9.6.tar.gz (3.2 MB) ERROR: Command errored out with exit status 1: command: 'c:\users\jerry\appdata\local\programs\python\python39\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\jerry\\AppData\\Local\\Temp\\pip-install-4b04m745\\pygame\\setup.py'"'"'; __file__='"'"'C:\\Users\\jerry\\AppData\\Local\\Temp\\pip-install-4b04m745\\pygame\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\jerry\AppData\Local\Temp\pip-pip-egg-info-up4741kz' cwd: C:\Users\jerry\AppData\Local\Temp\pip-install-4b04m745\pygame\ Complete output (17 lines): WARNING, No "Setup" File Exists, Running "buildconfig/config.py" Using WINDOWS configuration. Download prebuilts to "prebuilt_downloads" and copy to "./prebuilt-x64"? [Y/n]Traceback (most recent call last): File "", line 1, in File "C:\Users\jerry\AppData\Local\Temp\pip-install-4b04m745\pygame\setup.py", line 194, in buildconfig.config.main(AUTO_CONFIG) File "C:\Users\jerry\AppData\Local\Temp\pip-install-4b04m745\pygame\buildconfig\config.py", line 210, in main deps = CFG.main(**kwds) File "C:\Users\jerry\AppData\Local\Temp\pip-install-4b04m745\pygame\buildconfig\config_win.py", line 576, in main and download_win_prebuilt.ask(**download_kwargs): File "C:\Users\jerry\AppData\Local\Temp\pip-install-4b04m745\pygame\buildconfig\download_win_prebuilt.py", line 302, in ask reply = raw_input( EOFError: EOF when reading a line ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

4.2 Answer1.

  1. From the message you provide, we can see that you just install the Pygame version 1.9.6. And your python version is 3.9.
  2. But Pygame 1.9.6 does not support python 3.9 now. So you had better use python 3.8 instead.
  3. Or you can install Pygame 2.0 with the command pip install pygame==2.0.0,Pygame 2.0 support python 3.9.
  4. You can also download the Pygame wheel file from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame, it contains the wheel file pygame‑1.9.6‑cp39‑cp39‑win32.whl that meet your needs.

Источник

Оцените статью