如何让 Pygame 与 Pydev 一起工作?
我正在使用最新的 Mac 操作系统来尝试设置我的编程环境。现在我想做的是让 Pygame 与 Pydev 一起工作,这样我就可以从 Eclipse 进行 Python 编程。到目前为止,我所做的是从 python.org 安装 Python 2.6,然后从该站点安装 pygame 1.9。
发生的情况是,当我尝试从命令行运行 Python 时,我能够顺利导入 pygame,但是当我尝试从 Eclipse 执行相同的操作时,它不起作用。
我认为这可能是因为 Pydev 不知道在哪里可以找到 Python,在这种情况下,我需要一些帮助来确保它指向正确的 Python。
谢谢!
I'm working off the latest Mac OS trying to set up my programming environment. Right now what I want to do is to get Pygame working with Pydev so I can do my Python programming from Eclipse. What I've done so far is installed Python 2.6 from python.org and then installed pygame 1.9 from the site.
What happens is that when I try running Python from the command line, I am able to import pygame without a hitch, but when I try to do the same thing from Eclipse, it doesn't work.
I think it might be because Pydev doesn't know where to find Python, in which case I would like some help on how to make sure it's pointing to the right one.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我在Windows上使用Eclipse,但我相信Mac版本的eclipse应该是相同的。
在 Eclipse 中,
在eclipse中打开你的Python项目,
从 eclipse 构建您的项目,它应该可以工作。
I work with Eclipse on Windows, but I believe that the Mac version eclipse should be the same.
In Eclipse,
Turn to your Python project in eclipse,
Build your project from eclipse, and it should work.
在 Eclipse 中,Window->Preferences,展开 Pydev 并选择 Interpreter - Python。然后指定你的Python路径。首先尝试单击“自动配置”以自动定位您的 python 安装。然后单击“应用”和“确定”。
通过创建一个新的 Python 项目来确保这一切有效(暂时不用担心 Pygame)。
我在 Windows 上的 Eclipse Helios 中测试了这些指令。希望它对你有用。
http://www.vogella.de/articles/Python/article.html
In Eclipse, Window->Preferences, expand Pydev and choose Interpreter - Python. Then specify your python path. Try first by clicking "Auto Config" to auto-locate your python installation. Then click Apply and Ok.
Make sure this much works by creating a new Python project (without worrying about Pygame yet).
I tested these instructions from Eclipse Helios on Windows. Hope it works for you.
http://www.vogella.de/articles/Python/article.html
如果 autoconfig 没有找到 2.6,您可以在 Preferences/PyDev/Interpreter - Python 中手动添加它。您必须按“新建”并设置 Python 可执行文件的路径。
对于 Python2.6,路径为: /System/Library/Frameworks/Python.framework/Versions/2.6/bin/Python2.6
对于 Python2.7(及更高版本),路径不同:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
这些路径适用于 OS X 10.6.8,对于其他版本可能会更改。
If autoconfig is not finding 2.6 you can add it manually at Preferences/PyDev/Interpreter - Python. There you have to press New and set the path for your Python executable.
For Python2.6 the path is: /System/Library/Frameworks/Python.framework/Versions/2.6/bin/Python2.6
For Python2.7 (and higher), the path is different:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Those paths work on OS X 10.6.8, might change for other versions.
按照人们说的去做,如果这不起作用,请确保您已经下载了开发包。
Do what the people says, and if that does not work, make sure that you have downloaded the development package.
在菜单窗口>首选项> PyDev >口译员> Python 解释器
如果你的 python 解释器配置有 pygame 并且不起作用,请尝试强制添加新关键字“pygame”
On menu Window > Preferences > PyDev > Interpreters > Python Interpreters
If your python interpreter config have a pygame and don't work, try to put on force bultins the new keyword "pygame"
Python 部分
这应该安装pygame库。
Eclipse 部分
转到帮助>安装新软件。
在右上角查找“添加”按钮。
在位置中放置http://pydev.org/updates。也起个可爱的名字吧然后点击确定。
选中pyDev复选框。下一步,完成。接受许可。简而言之:安装它。
测试
尝试简单的代码
导入pygame
print(pygame.ver) # 这应该打印 pygame 版本。
pygame.init() # 现在这什么也不做,只是检查代码。
Python part
This should install the pygame library.
Eclipse Part
Go to Help>Install new software.
Look for the botton "Add" in the right top corner.
In Location put http://pydev.org/updates. Put a cute name, too. Then click OK.
Check pyDev checkbox. Go next, Finish. Accept licenses. In simple words: Install it.
Test
Try simple code
import pygame
print(pygame.ver) # This should print the pygame version.
pygame.init() # This does nothing by now, just checking code.
我一直浪费时间试图让它发挥作用。
我最终找到了这些步骤(你不需要它们全部只是我分享的斗争的一部分)。
在 Python Shell 中:
导入 sys
print (sys.path)
注意到路径中没有 PYGAME。
最终我放弃了 .exe 二进制文件,并被告知使用 .WHL 文件和 Python PIP 进行安装。但被告知无效的车轮文件。 (令人沮丧)。
最终有效的是(在Windows中,但类似的应该在其他操作系统中有效)。
以管理员身份运行命令提示符(只是为了确定)也许在其他操作系统中也是如此。你必须尝试一下。
从C:>我将目录更改为我的 Python.exe(或 python 程序本身)。
在命令提示符下的 python 目录中,我输入了以下内容(就像 Linux apt-get install 命令一样):
**
**
不久之后,出现井号#####,表明正在下载(shell 中的 Linux 类型进度条)。
在 ECLIPSE 中,无需更改 Libraries 文件夹以包含 PyGame 文件夹,我就能够运行示例 Python PYGAME 脚本示例(我得到了白屏,但还没有进一步进行)。我很高兴不必看到回溯错误消息:)
现在我已经完成向您输入此内容,我将进一步测试它。
只是认为这会对某人有所帮助:0)
I wasted forever trying to get this to work as well..
I eventually found these steps (you don't need them all just part of my struggles shared).
in Python Shell:
import sys
print (sys.path)
Noticed NO PYGAME in path.
Eventually I GAVE UP on the .exe binaries and was told to use .WHL files and Python PIP to install. but was told NOT VALID wheel file. (frustrating).
what EVENTUALLY WORKED was to (in windows, but similar should work in other OS's).
run Command Prompt as Administrator (just to be sure) Maybe same in other OS's. you'd have to try.
from C:> i Changed Dir to my Python.exe (or the python program itself).
from my python directory in command prompt I typed the following (Like I would a Linux apt-get install command):
**
**
Shortly after, there were hash marks ##### indicating a download was taking place (Linux type progress bar in shell).
in ECLIPSE without ever changing the Libraries folder to include PyGame folders I was able to run a sample Python PYGAME Script sample (I got a white screen but haven't gone further yet). I was just HAPPY to not have to see the trace back error message :)
now I am finished typing this to you I will be going to test it out further.
Just thought this would help someone :0)
我在Python 3.6中使用LiClipse(应该与Eclipse类似)遇到了这样的问题。可以通过 import pygame as 解决
,然后将 pygame 文件夹添加到 Window>Preferences>PyDev>Interpreters>PyDev>Libraries,在 ForcedbuiltIns 选项卡中输入“pygame”同一页面,也右键单击项目,将 Properties>PyDev-PYTHONPATH>Source 从 {proj_dir_name}/ 更改为 {proj_dir_name}/src
也许上面的一些步骤是不必要的。无论如何,执行上述所有操作就可以解决我的问题。
I met such problem in Python 3.6 using LiClipse (which should be similar as Eclipse). It's solved by import pygame as
Then add the pygame folder to Window>Preferences>PyDev>Interpreters>PyDev>Libraries, type in 'pygame' in the Forced BuiltIns tab at the same page, also right click the project, change Properties>PyDev-PYTHONPATH>Source from {proj_dir_name}/ to {proj_dir_name}/src
Maybe some above steps are not necessary. Anyway doing all aboves solves the problem in my case.