Gab*_*oni 6 python sublimetext sublimetext2
我是SublimeText2的新手.到目前为止,我发现它非常好,但我遇到了一个我无法解决的问题.我试图导入一个Python模块,机械化,到我的脚本.但是,每当运行它(只是导入机械化线),我得到:
Traceback (most recent call last):
File "/Users/gabrielbianconi/Desktop/test.py", line 1, in <module>
import mechanize
ImportError: No module named mechanize
[Finished in 0.3s with exit code 1]
Run Code Online (Sandbox Code Playgroud)
但是,当我在终端中运行此行时,它完美地工作:
gb-air:~ gabrielbianconi$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
>>>
Run Code Online (Sandbox Code Playgroud)
我猜这是ST2的一个问题.我看到Mac上的ST2使用系统的python,所以我不明白为什么它不能识别模块.
非常感谢你.
编辑:我在OS X Mountain Lion上.
Gab*_*oni 12
我设法解决了这个问题.ST2没有使用与终端相同的python.对于任何有同样错误的人,你可以通过选择:Sublime Text 2> Preferences> Browser Packages来解决这个问题......然后进入'Python'文件夹并打开'Python.sublime_build'.现在编辑'cmd'参数以匹配您想要的Python路径.对我来说(使用MacPorts),结果是:
{
"cmd": ["/opt/local/bin/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Run Code Online (Sandbox Code Playgroud)