Getting PyGame to import in Python interpreter after MacPorts install

血红的双手。 提交于 2019-12-12 04:35:03

问题


I'm trying to start using the pygame module but I can't get it to run. I'm using Mountain Lion with Python 2.7 and MacPorts, but I also installed some science and math modules using Anaconda before I ever discovered and started using MacPorts. Note that my MacPorts was just updated before I started any of the following. I initially tried to just use:

sudo port install py27-game

which looked like it worked and set everything up without a problem. But, when I go into the Python interpreter from the command line and type:

import pygame

I get the response:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: No module named pygame

So then I went in and did:

import sys
print sys.path

which gave:

 ['', '/Users/trav/anaconda/lib/python27.zip', '/Users/trav/anaconda/lib/python2.7',
 '/Users/trav/anaconda/lib/python2.7/plat-darwin',   
 '/Users/trav/anaconda/lib/python2.7/plat-mac',  
 '/Users/trav/anaconda/lib/python2.7/plat-mac/lib-scriptpackages', 
 '/Users/trav/anaconda/lib/python2.7/lib-tk', '/Users/trav/anaconda/lib/python2.7/lib-  
 old', '/Users/trav/anaconda/lib/python2.7/lib-dynload',  
 '/Users/trav/anaconda/lib/python2.7/site-packages', 
 '/Users/trav/anaconda/lib/python2.7/site-packages/PIL', 
 '/Users/trav/anaconda/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']

So, I'm guessing that because I used the Anaconda set up when I initially put the NumPy, SciPy & Matplotlib setup on here that this has caused MacPorts to clash with this somehow in the path.

Should I just remove the Ananconda package? If so, how can I go about removing these dependancies when I do that?


回答1:


Ok, so I figured out the problem, and it was my path. I went in and removed the anaconda package with:

rm -r ~/anaconda

Then, I used macports to basically reinstall the whole scipy stack with:

sudo port install py27-wxpython py27-numpy py27-matplotlib py27-scipy py27-ipython

This took some time to compile, and when it was finished I went in on the command line and used:

sudo port select --set python python27

After that I opened my interpreter and imported all my scientific computing needs without a problem and pygame, which I had installed earlier with macports. I hope this helps someone else in the future. ALSO: when you remove packages like anaconda, make sure and close your terminal and then re-open it or it will still try to use the dependancies of anaconda, which are no longer there. I had macports set up already so after removing anaconda the macports path became the default.

One last edit. In order to get all of this to run correctly and allow me to run the scripts from within emacs as well with all the imported modules I had to switch to aquamacs from my normal emacs editor in order for the correct path to be used from within the emacs environment , or I could have just run emacs from the terminal with /Application/Emacs.app/Contents/MacOS/Emacs.



来源:https://stackoverflow.com/questions/18262332/getting-pygame-to-import-in-python-interpreter-after-macports-install

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