I have the module pygame and tkinter installed on my computer, but I cannot find out how to access them in the text editor atom. I can use them in IDLE by using
import pygame
but when I try to import it in atom it doesn't recognize the module. Anybody know why? All of my other imports work by the way (time, random, etc.) but I think that they work because they come installed with python (right?).
解决方案
Firstly, atom is a text editor, it does not run python code by itself. So when you say you're trying to "import it in atom", I have to assume you're using an atom plugin that can interpret code. One common plugin for this is "script".
You need to head to the atom settings to check which python install is being used. Do this by first entering atom settings with control+,, then click on "packages" on the navagator, and click on "script" (or whatever plugin you're using to run your code, e.g. script, Hydrogen, atom-runner etc.). In the script settings, click on "view code", which will open the source code of script. On the tree nagivator on the left, navigate to script-->lib-->grammars-->python.coffee
In this coffeescript file, you should find the python interpreter that atom-script is using. For example, since I use anaconda, mine reads:
exports.Python =
'Selection Based':
command: '/home/username/.miniconda3/envs/local35/bin/python'
args: (context) -> ['-u', '-c', context.getCode()]
If you run linux or mac, now you can open a terminal and run
which python
import pygame should theoretically work if the system python matches the one atom is using, so these will probably be different. Just replace the python path in the coffeescript file with the result of which python. If these are already the same, this process should at least give you some clues to further diagnose the issue.
Personally, I recommend the use of Anaconda to keep track of your python environments and modules, it can really help with issues like this.
Also do make sure that python -c "import pygame" works, because if it doesn't, this isn't an atom issue at all.