且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

尝试在 SublimeText2 中导入 python 模块时出现导入错误

更新时间:2022-05-24 22:12:53

我设法解决了这个问题.ST2 没有使用与终端相同的 python.对于任何有同样错误的人,您可以通过选择来解决这个问题:Sublime Text 2 > Preferences > Browser Packages... 然后进入Python"文件夹并打开Python.sublime_build".现在编辑 'cmd' 参数以匹配您想要的 Python 路径.对我来说(使用 MacPorts),结果是:

I managed to solve this problem. ST2 was not using the same python as the Terminal. For anyone having the same mistake, you can solve this by selecting: Sublime Text 2 > Preferences > Browser Packages... Then go into 'Python' folder and open 'Python.sublime_build'. Now edit the 'cmd' parameter to match your desired Python path. For me (using MacPorts), the result was:

{
    "cmd": ["/opt/local/bin/python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}