eclipse 如何让 Pygame 与 Pydev 一起工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4524973/
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
How can I make Pygame work with Pydev?
提问by Catherine Hwang
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.
我正在尝试使用最新的 Mac OS 来设置我的编程环境。现在我想做的是让 Pygame 与 Pydev 一起工作,这样我就可以从 Eclipse 进行 Python 编程。到目前为止,我所做的是从 python.org 安装 Python 2.6,然后从该站点安装 pygame 1.9。
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.
发生的情况是,当我尝试从命令行运行 Python 时,我可以顺利导入 pygame,但是当我尝试从 Eclipse 执行相同操作时,它不起作用。
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.
我认为这可能是因为 Pydev 不知道在哪里可以找到 Python,在这种情况下,我需要一些帮助以确保它指向正确的 Python。
Thanks!
谢谢!
回答by Will.Cai
I work with Eclipse on Windows, but I believe that the Mac version eclipse should be the same. In Eclipse,
我在 Windows 上使用 Eclipse,但我相信 Mac 版本的 Eclipse 应该是一样的。在日食中,
- click Windows > Preferences,
- expand PyDev from left side,
- find Interpreter - Python,
- switch to Libraries tab,
- click New Folder on the right hand,
- navigate to your pygame path, and
- click Apply and OK.
- 单击 Windows > 首选项,
- 从左侧展开 PyDev,
- 找到解释器 - Python,
- 切换到库选项卡,
- 单击右侧的新建文件夹,
- 导航到您的 pygame 路径,然后
- 单击应用和确定。
Turn to your Python project in eclipse,
在 eclipse 中转到你的 Python 项目,
- right click on it,
- choose PyDev - Interpreter/Grammar,
- choose Python as Project type,
- choose 3.0 or your correspond Python version from Grammar,
- at last make sure the Interpreter you are using is the same as the one you just configured.
- 右键单击它,
- 选择 PyDev - 解释器/语法,
- 选择 Python 作为项目类型,
- 从 Grammar 中选择 3.0 或相应的 Python 版本,
- 最后确保您使用的解释器与您刚刚配置的解释器相同。
Build your project from eclipse, and it should work.
从 Eclipse 构建您的项目,它应该可以工作。
回答by Sebastian
Do what the people says, and if that does not work, make sure that you have downloaded the development package.
按照人家说的做,如果不行,请确保您已经下载了开发包。
回答by Nenodias
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"
在菜单 Window > Preferences > PyDev > Interpreters > Python Interpreters 如果你的 python 解释器配置有一个 pygame 并且不工作,尝试强制使用新关键字“pygame”
回答by Germán Acosta
Python part
蟒蛇部分
- Install Python 3.5.2 32 bits (From python.org)
- Download the right pyGame library for 3.5.x 32 bits (It will be pygame-1.9.2b1-cp35-cp35m-win32.whl)
- Open the system console and go to the folder where the library was download.
- Write in the console: pip install pygame-1.9.2b1-cp35-cp35m-win32.whl
This should install the pygamelibrary.
- 安装 Python 3.5.2 32 位(来自python.org)
- 为 3.5.x 32 位下载正确的 pyGame 库(它将是pygame-1.9.2b1-cp35-cp35m-win32.whl)
- 打开系统控制台并转到下载库的文件夹。
- 在控制台写: pip install pygame-1.9.2b1-cp35-cp35m-win32.whl
这应该安装pygame库。
Note: If the pip version is not the last one, upgrade it. (In this step you should know how, just pay attention.)
注意:如果pip版本不是最后一个,请升级。(这一步你应该知道怎么做,注意就好。)
Eclipse Part
日蚀部分
- Open Eclipse
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 pyDevcheckbox. Go next, Finish. Accept licenses. In simple words: Install it.
- 打开日食
转到帮助>安装新软件。
在右上角寻找按钮“添加”。
在 Location 中放置http://pydev.org/updates。也取个可爱的名字吧。然后单击确定。
选中pyDev复选框。下一步,完成。接受许可证。简单来说:安装它。
- Go to Window>Preferences>pyDev>Interpreters>Phyton interpreter.
- In the Pythoninterpreters part, click Quick Auto-Config.
- 转到窗口>首选项>pyDev>解释器>Phyton解释器。
- 在Python解释器部分,单击Quick Auto-Config。
Note: If you want to do this manually, you should know the path where you installed Pythonand search for python.exe
注意:如果您想手动执行此操作,您应该知道安装Python的路径并搜索python.exe
- Some libraries should manifest in the libraries tab. Click apply.
- In the libraries tab, click New Folder.
- Search for PyGameinstallation path (In my case, C:\Python\Python35-32\include\pygamebut it's always on Python installation path plus include\pygame, ok?)
- Click Accept.
- Go to Forced Builtinstab. Click New...and add 'pygame'.
- Applyagain ! (You should know that I do this only for safety. You can apply just one time.
- Click OK.
- 某些库应显示在库选项卡中。单击应用。
- 在库选项卡中,单击新建文件夹。
- 搜索PyGame安装路径(在我的例子中,C:\Python\Python35-32\include\pygame但它总是在 Python 安装路径加上 include\pygame,好吗?)
- 单击接受。
- 转到强制内置选项卡。单击New...并添加'pygame'。
- 再次申请!(你应该知道我这样做只是为了安全。你只能申请一次。
- 单击“确定”。
Test
测试
- File> New> Proyect...> PyDev> PyDev Proyect.
- Click Next
- Complete the Proyect Name. On Grammar Versioncombobox, select 3.0 - 3.5and in interpreter choose python.
- 文件> 新建> 项目...> PyDev> PyDev 项目。
- 单击下一步
- 填写项目名称。在Grammar Version组合框上,选择3.0 - 3.5并在解释器中选择python。
Note: "Quick Auto-Config"named "python"to the interpreter. If you did this part manually, you should know the exact name because you named it.
注:“快速自动配置”命名的“蟒蛇”的解释。如果你手动完成了这部分,你应该知道确切的名字,因为你给它命名了。
Try simple code
import pygame
print(pygame.ver) # This should print the pygame version.
pygame.init() # This does nothing by now, just checking code.
尝试简单的代码
import pygame
print(pygame.ver) # 这应该打印 pygame 版本。
pygame.init() # 现在什么都不做,只是检查代码。
回答by James B
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:
在 Python Shell 中:
import sys print (sys.path)
导入系统打印(sys.path)
Noticed NO PYGAME in path.
注意到路径中没有 PYGAME。
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).
最终我放弃了 .exe 二进制文件,并被告知使用 .WHL 文件和 Python PIP 进行安装。但被告知 NOT VALID 轮文件。(令人沮丧)。
what EVENTUALLY WORKED was to (in windows, but similar should work in other OS's).
最终有效的是(在 Windows 中,但类似的应该适用于其他操作系统)。
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).
从 C:> 我将 Dir 更改为我的 Python.exe(或 python 程序本身)。
from my python directory in command prompt I typed the following (Like I would a Linux apt-get install command):
从命令提示符的 python 目录中,我输入了以下内容(就像我输入 Linux apt-get install 命令一样):
**
**
python.exe -m pip install pygame
python.exe -m pip install pygame
**
**
Shortly after, there were hash marks ##### indicating a download was taking place (Linux type progress bar in shell).
不久之后,有井号##### 表示正在下载(shell 中的 Linux 类型进度条)。
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 :)
在 ECLIPSE 中,没有更改 Libraries 文件夹以包含 PyGame 文件夹,我能够运行示例 Python PYGAME 脚本示例(我得到了一个白屏,但还没有更进一步)。我很高兴不必看到回溯错误消息:)
now I am finished typing this to you I will be going to test it out further. Just thought this would help someone :0)
现在我已经完成了给你的输入,我将进一步测试它。只是认为这会帮助某人:0)
回答by Zoe04
I met such problem in Python 3.6 using LiClipse (which should be similar as Eclipse). It's solved by import pygame as
我在使用 LiClipse(应该类似于 Eclipse)的 Python 3.6 中遇到了这样的问题。它通过 import pygame as 解决
import pygame
from pygame.locals import *
Then add the pygame folder to Window>Preferences>PyDev>Interpreters>PyDev>Libraries, type in 'pygame' in the Forced BuiltInstab at the same page, also right click the project, change Properties>PyDev-PYTHONPATH>Source from {proj_dir_name}/to {proj_dir_name}/src
然后将 pygame 文件夹添加到Window>Preferences>PyDev>Interpreters>PyDev>Libraries,在同一页面的Forced BuiltIns选项卡中输入“pygame” ,同时右键单击该项目,更改 Properties>PyDev-PYTHONPATH>Source from {proj_dir_name }/到{proj_dir_name}/src
Maybe some above steps are not necessary. Anyway doing all aboves solves the problem in my case.
也许上面的一些步骤是不必要的。无论如何,在我的情况下,执行以上所有操作都可以解决问题。
回答by Travis
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.
在 Eclipse 中,Window->Preferences,展开 Pydev 并选择 Interpreter - Python。然后指定你的python路径。首先尝试单击“自动配置”以自动定位您的 python 安装。然后单击应用和确定。
Make sure this much works by creating a new Python project (without worrying about Pygame yet).
通过创建一个新的 Python 项目来确保这一切正常(现在不用担心 Pygame)。
I tested these instructions from Eclipse Helios on Windows. Hope it works for you.
我在 Windows 上从 Eclipse Helios 测试了这些指令。希望对你有效。
回答by Karlos Zafra
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.
如果 autoconfig 没有找到 2.6,您可以在 Preferences/PyDev/Interpreter - Python 中手动添加它。在那里,您必须按 New 并设置 Python 可执行文件的路径。
For Python2.6 the path is: /System/Library/Frameworks/Python.framework/Versions/2.6/bin/Python2.6
对于 Python2.6,路径是:/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
对于 Python2.7(及更高版本),路径不同:/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Those paths work on OS X 10.6.8, might change for other versions.
这些路径适用于 OS X 10.6.8,对于其他版本可能会发生变化。