1

如何在 Windows 7(64 位)上安装 Pygame?我已经尝试了我能想到的一切,但没有任何效果。

我正在运行 CPython 2.7.3 32 位。

通过pip install pygamefrom安装cmd失败并出现错误(是的,我安装了 MinGW)

  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command

    cmd_obj.run()

  File "c:\users\r\appdata\local\temp\pip-build-R\pygame\setup.py", line 325, in
 run

    "mingw32: required environment variable"

RuntimeError: mingw32: required environment variable MINGW_ROOT_DIRECTORY not se
t

----------------------------------------
Command C:\Python27\python.exe -c "import setuptools;__file__='c:\\users\\r\\app
data\\local\\temp\\pip-build-R\\pygame\\setup.py';exec(compile(open(__file__).re
ad().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\r\appd
ata\local\temp\pip-vi1djm-record\install-record.txt --single-version-externally-
managed failed with error code 1 in c:\users\r\appdata\local\temp\pip-build-R\py
game 

设置MINGW_ROOT_DIRECTORY=C:\MinGW并重试后,我得到了错误

Downloading/unpacking pygame
  Running setup.py egg_info for package pygame
    WARNING, DLL for smpeg library not found.
    WARNING, DLL for tiff library not found.
    WARNING, DLL for SDL_ttf library not found.
    WARNING, DLL for SDL_image library not found.
    WARNING, DLL for vorbisfile library not found.
    WARNING, DLL for jpeg library not found.
    WARNING, DLL for vorbis library not found.
    WARNING, DLL for SDL_mixer library not found.
    WARNING, DLL for png library not found.
    WARNING, DLL for SDL library not found.
    WARNING, DLL for ogg library not found.
    WARNING, DLL for z library not found.
    WARNING, DLL for portmidi library not found.

    warning: no files found matching 'readme.txt'
    no previously-included directories found matching '*\CVS'
    no previously-included directories found matching '*\*\CVS'
Installing collected packages: pygame
  Running setup.py install for pygame
    WARNING, DLL for smpeg library not found.
    WARNING, DLL for tiff library not found.
    WARNING, DLL for SDL_ttf library not found.
    WARNING, DLL for SDL_image library not found.
    WARNING, DLL for vorbisfile library not found.
    WARNING, DLL for jpeg library not found.
    WARNING, DLL for vorbis library not found.
    WARNING, DLL for SDL_mixer library not found.
    WARNING, DLL for png library not found.
    WARNING, DLL for SDL library not found.
    WARNING, DLL for ogg library not found.
    WARNING, DLL for z library not found.
    WARNING, DLL for portmidi library not found.
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\r\appdata\local\temp\pip-build-R\pygame\setup.py", line 491
, in <module>
        setup(**PACKAGEDATA)
      File "C:\Python27\lib\distutils\core.py", line 152, in setup
        dist.run_commands()
      File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
        cmd_obj.run()
      File "C:\Python27\lib\site-packages\distribute-0.6.38-py2.7.egg\setuptools
\command\install.py", line 53, in run
        return _install.run(self)
      File "C:\Python27\lib\distutils\command\install.py", line 563, in run
        self.run_command('build')
      File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
        cmd_obj.run()
      File "C:\Python27\lib\distutils\command\build.py", line 127, in run
        self.run_command(cmd_name)
      File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
        cmd_obj.run()
      File "c:\users\r\appdata\local\temp\pip-build-R\pygame\setup.py", line 352
, in run
        sys.version_info[:2])
    RuntimeError: The dependencies are linked to the wrong C runtime for Python
2.7
    Complete output from command C:\Python27\python.exe -c "import setuptools;__
file__='c:\\users\\r\\appdata\\local\\temp\\pip-build-R\\pygame\\setup.py';exec(
compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install
 --record c:\users\r\appdata\local\temp\pip-xe1cpi-record\install-record.txt --s
ingle-version-externally-managed:
    WARNING, DLL for smpeg library not found.

WARNING, DLL for tiff library not found.

WARNING, DLL for SDL_ttf library not found.

WARNING, DLL for SDL_image library not found.

WARNING, DLL for vorbisfile library not found.

WARNING, DLL for jpeg library not found.

WARNING, DLL for vorbis library not found.

WARNING, DLL for SDL_mixer library not found.

WARNING, DLL for png library not found.

WARNING, DLL for SDL library not found.

WARNING, DLL for ogg library not found.

WARNING, DLL for z library not found.

WARNING, DLL for portmidi library not found.

running install

running build

running build_py

running build_ext

Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "c:\users\r\appdata\local\temp\pip-build-R\pygame\setup.py", line 491, in
 <module>

    setup(**PACKAGEDATA)

  File "C:\Python27\lib\distutils\core.py", line 152, in setup

    dist.run_commands()

  File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands

    self.run_command(cmd)

  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command

    cmd_obj.run()

  File "C:\Python27\lib\site-packages\distribute-0.6.38-py2.7.egg\setuptools\com
mand\install.py", line 53, in run

    return _install.run(self)

  File "C:\Python27\lib\distutils\command\install.py", line 563, in run

    self.run_command('build')

  File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command

    self.distribution.run_command(command)

  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command

    cmd_obj.run()

  File "C:\Python27\lib\distutils\command\build.py", line 127, in run

    self.run_command(cmd_name)

  File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command

    self.distribution.run_command(command)

  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command

    cmd_obj.run()

  File "c:\users\r\appdata\local\temp\pip-build-R\pygame\setup.py", line 352, in
 run

    sys.version_info[:2])

RuntimeError: The dependencies are linked to the wrong C runtime for Python 2.7

----------------------------------------
Command C:\Python27\python.exe -c "import setuptools;__file__='c:\\users\\r\\app
data\\local\\temp\\pip-build-R\\pygame\\setup.py';exec(compile(open(__file__).re
ad().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\r\appd
ata\local\temp\pip-xe1cpi-record\install-record.txt --single-version-externally-
managed failed with error code 1 in c:\users\r\appdata\local\temp\pip-build-R\py
game
Storing complete log in C:\Users\R\pip\pip.log

二进制安装程序也不起作用。当我尝试运行安装程序时,菜单显示“来自其他位置的 Python - 整个功能将不可用”。如果我仍然继续,安装成功完成,但尝试导入 Pygame 仍然说没有这样的模块。我不确定它是否安装失败,或者它是否确实安装但没有正确更新路径,或者什么,但无论哪种方式它都不起作用。

我能做些什么?我无计可施。

4

2 回答 2

0

几个月前,我在安装其他一些库(可能是 PyTables)时遇到了一个完全不同的问题。我在这里找到了一个很棒的(但非官方的)用于 Python 库的 Windows 二进制文件的资源。我能够毫无问题地安装很多这样的二进制文件。

如果你想解决这个问题,我建议进入 setup.py 的源代码(第 345 行):

def run(self):
        """Extended to set MINGW_ROOT_DIRECTORY, PATH and LIBRARY_PATH"""

        if self.compiler in mingw32_compilers:
            # Add MinGW environment variables.
            if 'MINGW_ROOT_DIRECTORY' not in os.environ:
                # Use MinGW setup conifiguration file if present.
                import mingwcfg
                try:
                    mingw_root = mingwcfg.read()
                except IOError:
                    raise RuntimeError(
                        "mingw32: required environment variable"
                        " MINGW_ROOT_DIRECTORY not set")
                os.environ['MINGW_ROOT_DIRECTORY'] = mingw_root
                path = os.environ['PATH']
                os.environ['PATH'] = ';'.join([os.path.join(mingw_root, 'bin'),
                                               path])
            if sys.version_info >= (2, 6):
                # The Visual Studio 2008 C library is msvcr90.dll.
                c_runtime_path = os.path.join(self.__sdl_lib_dir, 'msvcr90')
            elif sys.version_info >= (2, 4):
                # The Visual Studio 2003 C library is msvcr71.dll.
                c_runtime_path = os.path.join(self.__sdl_lib_dir, 'msvcr71')
            else:
                # The Visual Studio 6.0 C library is msvcrt.dll,
                # the MinGW default.
                c_runtime_path = ''
            if c_runtime_path and os.path.isdir(c_runtime_path):
                # Override the default msvcrt.dll linkage.
                os.environ['LIBRARY_PATH'] = c_runtime_path
            elif not (c_runtime_path or
                      glob.glob(os.path.join(self.__sdl_lib_dir,
                                             'msvcr*'))):
                pass
            else:
                raise RuntimeError("The dependencies are linked to"
                                   " the wrong C runtime for"
                                   " Python %i.%i" %
                                   sys.version_info[:2]

初步看,这个问题好像你没有最新的 Microsoft Visual C++ 运行时,你可以从这里下载。希望这可以帮助。

于 2013-10-13T18:53:05.820 回答
0

如果您在安装 pygame 时遇到有关缺少 Visual Studio 10+ 的错误。我有答案:问题不在于有没有 Visual Studio,因为我尝试了很多版本但它不起作用。问题是 file: 在 tar.gz 和 .whl 之间所以,这是解决方案:

  1. 下载文件:

    http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
    去这里下载你的pygame版本,注意x64或x86和python版本。我的系统是 x64,python 是 3.4 所以我选择:pygame-1.9.2a0-cp34-none-win_amd64.whl

  2. 把它放在一些安装位置:

    我把它放在“C:”中,所以打开cmd并输入:

    cd C:\ 
    

    (这是将位置更改为 C :)

  3. 安装

    pip install C:\pygame-1.9.2a0-cp34-none-win_amd64.whl
    

完毕!

于 2016-01-26T12:05:16.063 回答