在python中的atom中添加模块 [英] Adding modules in atom in python

查看:452
本文介绍了在python中的atom中添加模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算机上安装了pygame和tkinter模块,但是我无法在文本编辑器原子中找到如何访问它们的方法.我可以通过

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 

但是当我尝试将其导入atom时,它无法识别该模块.有人知道为什么吗?我所有其他导入方式都可以工作(时间,随机等),但是我认为它们可以工作是因为它们是使用python安装的(对吗?).

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?).

推荐答案

首先,atom是一个文本编辑器,它本身不会运行python代码.因此,当您说要尝试将其导入atom"时,我必须假设您使用的是可解释代码的atom插件.一个常见的插件是脚本".

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".

您需要转到atom设置来检查正在使用的python安装.为此,请先使用control+,输入原子设置,然后在导航器上单击程序包",然后单击脚本"(或用于运行代码的任何插件,例如脚本,Hydrogen,atom-runner等).在脚本设置中,单击查看代码",这将打开脚本的源代码.在左侧的树导航器上,导航至脚本-> lib->语法-> python.coffee

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

在此coffeescript文件中,您应该找到atom-script使用的python解释器.例如,由于我使用蟒蛇,我的读法是:

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()]

如果您运行linux或mac,现在可以打开一个终端并运行

If you run linux or mac, now you can open a terminal and run

which python

如果系统python匹配正在使用的一个原子,则

import pygame在理论上应该可以工作,因此它们可能会有所不同.只需将咖啡脚本文件中的python路径替换为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.

我个人建议使用Anaconda来跟踪您的python环境和模块,它确实可以帮助解决此类问题.

Personally, I recommend the use of Anaconda to keep track of your python environments and modules, it can really help with issues like this.

还要确保python -c "import pygame"可以正常工作,因为如果不能,那么这根本不是原子问题.

Also do make sure that python -c "import pygame" works, because if it doesn't, this isn't an atom issue at all.

这篇关于在python中的atom中添加模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆