Python 在 PyCharm IDE 中添加 pygame 模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28453854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:18:31  来源:igfitidea点击:

Add pygame module in PyCharm IDE

pythonpython-2.7terminalpygamepycharm

提问by lavee_singh

I've downloaded pygame-1.9.1release.tar.gzfrom the Pygame website. I extracted and installed it and it's working fine in the command line Python interpreter in Terminal (Ubuntu). But I want to install it for some IDE, like PyCharm. How can I do it?

我是pygame-1.9.1release.tar.gz从 Pygame 网站下载的。我提取并安装了它,它在终端(Ubuntu)的命令行 Python 解释器中运行良好。但我想为一些 IDE 安装它,比如 PyCharm。我该怎么做?

采纳答案by Anthony Pham

Well, you don't have to download it for PyCharm here. You probably know how it checks your code. Through the interpreter! You don't need to use complex command lines or anything like that. You need to is:

好吧,您不必在此处为 PyCharm 下载它。您可能知道它如何检查您的代码。通过翻译!您不需要使用复杂的命令行或类似的东西。你需要的是:

  • Download the appropriate interpreter withPyGame included

  • Open your PyCharm IDE (Make sure it is up to date)

  • Go to File

  • Press Settings(Or Ctrl + Alt + S)

  • Double clickon the option that looks like Project: Name_of_Project

  • Click on Project Interpreter

  • Choose the interpreter you want to use that includesPyGame as a module

  • Save your options

  • 下载包含PyGame的适当解释器

  • 打开您的 PyCharm IDE(确保它是最新的)

  • File

  • Settings(或 Ctrl + Alt + S)

  • 双击看起来像的选项Project: Name_of_Project

  • 点击 Project Interpreter

  • 选择您要使用的包含PyGame 作为模块的解释器

  • 保存您的选项

And you are ready to go! Here is an alternate (I have never done this, please try to test it)

你准备好了!这是一个替代方案(我从未这样做过,请尝试测试)

  • Add PyGame in the same folder as your PyCharm file (Your PyCharm stuff is always in a specific file placed by youduring installation/upgrade) Please consider putting your PyCharm stuff inside a folder for easy access.
  • 将 PyGame 添加到与您的 PyCharm 文件相同的文件夹中(您的 PyCharm 内容始终位于在安装/升级期间放置的特定文件中)请考虑将您的 PyCharm 内容放在一个文件夹中以便于访问。

I hope this helps you!

我希望这可以帮助你!

回答by Rain

I just figured it out!

我刚刚想通了!

  1. Put the .whlfile in C:\Program Files\Anaconda3
  2. While in the folder, click on the blue Filetab in the upper left corner of the Window Explorer (assuming you're using Windows)
  3. Click on Open Windows PowerShell as administrator
  4. Write or just copy and paste: py -m pip install pygame
  5. It should start installing
  6. Done!
  1. .whl文件放进去C:\Program Files\Anaconda3
  2. 在文件夹中,单击窗口资源管理器左上角的蓝色文件选项卡(假设您使用的是 Windows)
  3. 单击以管理员身份打开 Windows PowerShell
  4. 写或只是复制和粘贴: py -m pip install pygame
  5. 它应该开始安装
  6. 完毕!

I hope it works for you. I know it did for me.

我希望这个对你有用。我知道这对我有用。

回答by Don Trapp

If you are using PyCharm and you are on a Windows 10 machine use the following instructions:

如果您使用 PyCharm 并且您使用的是 Windows 10 机器,请使用以下说明:

  1. Click on the Windows start menu and type cmdand click on the Command Prompt icon.

  2. Use the command pushdto navigate to your PyCharm project which should be located in your user folder on the C:\ drive. Example: C:\Users\username\PycharmProjects\project name\venv\Scripts.

    (If you are unsure go to the settings within PyCharm and navigate to the Python Interpreter settings. This should show you the file path for the interpreter that your project is using. Credit to Anthony Pham for instructions to navigate to interpreter settings.)

    HINT: Use copy and paste in the command prompt to paste in the file path.

  3. Use the command pip install pygameand the pip program will handle the rest for you.

  4. Restart you Pycharm and you should now be able to import pygame

  1. 单击 Windows 开始菜单并键入cmd,然后单击命令提示符图标。

  2. 使用命令pushd导航到您的 PyCharm 项目,该项目应位于 C:\ 驱动器上的用户文件夹中。示例:C:\Users\username\PycharmProjects\project name\venv\Scripts

    (如果您不确定,请转到 PyCharm 中的设置并导航到 Python 解释器设置。这应该会显示您的项目正在使用的解释器的文件路径。感谢Anthony Pham 提供导航到解释器设置的说明。

    提示:在命令提示符下使用复制和粘贴来粘贴文件路径。

  3. 使用命令pip install pygame,pip 程序将为您处理其余的工作。

  4. 重启你的 Pycharm,你现在应该可以导入pygame

Hope this helps. I had a fun time trying to find out the correct way to get it installed, so hopefully this helps someone out in the future.

希望这可以帮助。我在尝试找出安装它的正确方法时玩得很开心,所以希望这对将来的人有所帮助。

回答by Sergey K

For PyCharm 2017 do the following:

对于 PyCharm 2017,请执行以下操作:

  • File - Settings
  • Double click on your project name
  • Select Project Interpreter
  • Click on green + button on the right side of the window
  • Type Pygame in search window
  • Click Install package.
  • 文件 - 设置
  • 双击您的项目名称
  • 选择项目口译员
  • 单击窗口右侧的绿色 + 按钮
  • 在搜索窗口中输入 Pygame
  • 单击安装包。

Not I'm saying that the answers above won't work, but it might be frustrating to a newbie to do command line magic.

不是我说上面的答案不起作用,但是对于新手来说执行命令行魔术可能会令人沮丧。