How do you import pygame libraries into Eclipse's pydev?

人盡茶涼 提交于 2019-12-12 02:39:04

问题


I have Eclipse working and am working uder the Pydev plugin, and I need some help with pygame. I'm on a mac and have managed to get pygame working for python 3.3 using homebrew, and pydev's causing me some trouble. The libraries don't seem to be recognized. I can use pygame as needed, doing things like

import pygame

and

pygame.init()

without problem, but Eclipse doesn't recognize the modules and says things like

unresolved import: pygame

Again, I think the issue here is Eclipse not having access to the pygame libraries. How do I fix this?


回答1:


Windows > Preferences > pydev

look for the python interpreter line

on the libraries tab, click new folder and add the pygame folder path, apply and you're done

NOTE : make sure to use python 3.x as the project interpreter




回答2:


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 are shared here).

in Python Shell:

import sys
print (sys.path)

I noticed that no PYGAME appeared 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.

What EVENTUALLY WORKED was (in windows, but similar should work in other OS's) to run Command Prompt as Administrator (just to be sure). Maybe the solution will also work 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 in a linux apt-get install command):

python.exe -m pip install pygame

Shortly after, ther ewere 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.

Just thought this would help someone.




回答3:


python.exe -m pip install pygame [Worked perfectly]



来源:https://stackoverflow.com/questions/13126067/how-do-you-import-pygame-libraries-into-eclipses-pydev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!