如何在Windows 7上安装Pygame?

时间:2013-10-13 18:24:08

标签: python windows pygame

如何在Windows 7(64位)上安装Pygame?我已经尝试了所有我能想到的但没有任何作用。

我正在运行CPython 2.7.3 32位。

pip install pygame通过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仍然没有说这样的模块。我不确定它是否安装失败,或者它是否实际安装但是没有更新路径正确,或者是什么,但无论哪种方式都不起作用。

我该怎么办?我的智慧结束了。

2 个答案:

答案 0 :(得分:0)

几个月前,我在安装其他库(可能是PyTables)方面遇到了完全不同的问题。我找到了一个很好的(但非官方的)资源,用于Python库here的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 ++运行时,可以从here下载。希望这会有所帮助。

答案 1 :(得分:0)

如果您在安装pygame错误时遇到麻烦,请注意缺少visual studio 10+。我有答案:问题不在于是否有视觉工作室,因为我尝试了很多版本但它不起作用。问题是文件:在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
    
  4. 完成!