atom python 插件,在python中的atom中添加模块

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值